Wait for the module to load to run the tests it contains.

My unit tests are contained in a module that is loaded from an HTML page using SystemJS.

<script src="node_modules/systemjs/dist/system.src.js"></script> <script src="node_modules/rxjs/bundles/Rx.js"></script> <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script> <script src="node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script> <script src="node_modules/jasmine-core/lib/jasmine-core/boot.js"></script> <script> System.config({ defaultJSExtensions: true, map: { "angular2": 'http://localhost:8000/angular2', "rxjs": 'node_modules/rxjs' }, packages: { angular2: { defaultExtension: 'js', } } }); System.import('angular2/test/http/backends/xhr_backend_spec') .then((src) => { src.main(); }); </script> 

My page does not show any tests, while my main method contains a set of tests:

 export function main() { console.log('in main'); describe('XHRBackend', () => { (...) }); } 

I put some traces, and I check that the main function and the callback defined in the description function are called. But the tests themselves are not executed in the describe callback.

I assume that I need to wait for the module to load before starting Jasmine, but I do not know how to configure it.

Thank you for your help!

+2
jasmine systemjs
source share
1 answer

Tell Jasmine to run imported tests with .then (window.onload)

 <script> System.config({ (...) System.import('angular2/test/http/backends/xhr_backend_spec') // wait for all imports to load ... // then re-execute `window.onload` which // triggers the Jasmine test-runner start .then(window.onload) (...) </script> 

I read how to run Jasmine tests on angular.io

https://angular.io/docs/ts/latest/testing/first-app-tests.html

+2
source share

All Articles