-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): Added initial unit tests for loader
- Loading branch information
1 parent
84c8562
commit 824cc57
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules | ||
|
||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var should = require('should'); | ||
var loader = require('../src/index'); | ||
|
||
function checkResult(loaded, result) { | ||
return loaded.should.eql(result.join('')); | ||
} | ||
|
||
describe('Loader', function() { | ||
var resourcePath = 'path/to/routes.ts'; | ||
var modulePath = './path/to/file.module#FileModule'; | ||
var query = ''; | ||
|
||
it('should return a loadChildren async require statement', function() { | ||
var loadedString = loader.call({ | ||
resourcePath: resourcePath, | ||
query: query | ||
}, `loadChildren: '${modulePath}'`); | ||
|
||
var result = [ | ||
'loadChildren: () => new Promise(function (resolve) {\n', | ||
' (require as any).ensure([], function (require) {\n', | ||
' resolve(require(\'./path/to/file.module\')[\'FileModule\']);\n', | ||
' });\n', | ||
'})' | ||
]; | ||
|
||
checkResult(loadedString, result); | ||
}); | ||
|
||
it('should return a loadChildren sync require statement', function() { | ||
var loadedString = loader.call({ | ||
resourcePath: resourcePath, | ||
query: query | ||
}, `loadChildren: '${modulePath}?sync=true'`); | ||
|
||
var result = [ | ||
'loadChildren: function() {\n', | ||
' return require(\'./path/to/file.module\')[\'FileModule\'];\n', | ||
'}' | ||
]; | ||
|
||
checkResult(loadedString, result); | ||
}); | ||
|
||
it ('should return a loadChildren System.import statement', function() { | ||
var loadedString = loader.call({ | ||
resourcePath: resourcePath, | ||
query: '?loader=system' | ||
}, `loadChildren: '${modulePath}'`); | ||
|
||
var result = [ | ||
'loadChildren: () => System.import(\'./path/to/file.module\')\n', | ||
' .then(function(module) {\n', | ||
' return module[\'FileModule\'];\n', | ||
' })' | ||
]; | ||
|
||
checkResult(loadedString, result); | ||
}); | ||
}); |