Skip to content

Commit dccb762

Browse files
authored
test: add tests for "renderer" module (#110)
1 parent 7bd855e commit dccb762

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

__tests__/core/renderer.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const ejs = require('ejs');
2+
const renderer = require('../../lib/core/renderer');
3+
4+
describe('code.renderer', () => {
5+
beforeEach(() => {
6+
ejs.renderFile = jest.fn();
7+
});
8+
9+
it('should call ejs render method', () => {
10+
const cb = () => {};
11+
12+
renderer('my-template', { props: ['props'], data: ['data'], computed: ['computed'] }, cb);
13+
14+
expect(ejs.renderFile).toHaveBeenCalledTimes(1);
15+
expect(ejs.renderFile).toHaveBeenCalledWith(
16+
'my-template',
17+
{
18+
props: ['props'],
19+
data: ['data'],
20+
computed: ['computed'],
21+
// an helper function, it should be under keys "utils" or "helpers" btw
22+
renderType: expect.any(Function),
23+
},
24+
cb,
25+
);
26+
});
27+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Actually stub this module, to prevent follow error:
2+
// "Cannot find module 'jsdoc/tag/dictionary' from 'templateHelper.js'" :)
3+
4+
module.exports = {};

jest.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ module.exports = {
88
testPathIgnorePatterns: [
99
'/node_modules/',
1010
'/__fixtures__/',
11+
'/__tests__/stubs',
1112
'/cypress/',
1213
],
14+
moduleNameMapper: {
15+
'jsdoc/(.*)': '<rootDir>/__tests__/stubs/jsdoc/$1.js',
16+
},
1317
};

0 commit comments

Comments
 (0)