Skip to content

Commit 824cc57

Browse files
feat(tests): Added initial unit tests for loader
1 parent 84c8562 commit 824cc57

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules
2-
2+
npm-debug.log

spec/index.spec.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
var should = require('should');
2+
var loader = require('../src/index');
3+
4+
function checkResult(loaded, result) {
5+
return loaded.should.eql(result.join(''));
6+
}
7+
8+
describe('Loader', function() {
9+
var resourcePath = 'path/to/routes.ts';
10+
var modulePath = './path/to/file.module#FileModule';
11+
var query = '';
12+
13+
it('should return a loadChildren async require statement', function() {
14+
var loadedString = loader.call({
15+
resourcePath: resourcePath,
16+
query: query
17+
}, `loadChildren: '${modulePath}'`);
18+
19+
var result = [
20+
'loadChildren: () => new Promise(function (resolve) {\n',
21+
' (require as any).ensure([], function (require) {\n',
22+
' resolve(require(\'./path/to/file.module\')[\'FileModule\']);\n',
23+
' });\n',
24+
'})'
25+
];
26+
27+
checkResult(loadedString, result);
28+
});
29+
30+
it('should return a loadChildren sync require statement', function() {
31+
var loadedString = loader.call({
32+
resourcePath: resourcePath,
33+
query: query
34+
}, `loadChildren: '${modulePath}?sync=true'`);
35+
36+
var result = [
37+
'loadChildren: function() {\n',
38+
' return require(\'./path/to/file.module\')[\'FileModule\'];\n',
39+
'}'
40+
];
41+
42+
checkResult(loadedString, result);
43+
});
44+
45+
it ('should return a loadChildren System.import statement', function() {
46+
var loadedString = loader.call({
47+
resourcePath: resourcePath,
48+
query: '?loader=system'
49+
}, `loadChildren: '${modulePath}'`);
50+
51+
var result = [
52+
'loadChildren: () => System.import(\'./path/to/file.module\')\n',
53+
' .then(function(module) {\n',
54+
' return module[\'FileModule\'];\n',
55+
' })'
56+
];
57+
58+
checkResult(loadedString, result);
59+
});
60+
});

0 commit comments

Comments
 (0)