Skip to content

Commit

Permalink
feat(tests): Added initial unit tests for loader
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts committed Sep 18, 2016
1 parent 84c8562 commit 824cc57
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules

npm-debug.log
60 changes: 60 additions & 0 deletions spec/index.spec.js
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);
});
});

0 comments on commit 824cc57

Please sign in to comment.