2

My unit tests are contained into a module that loads 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 doesn't display any tests whereas my main method contains a test suite:

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 describe function are called. But the tests themselves aren't executed within the describe callback.

I guess that I need to wait for the module to be loaded before running Jasmine but I don't know how to configure this.

Thanks for your help!

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • 1
    would something like require.js be a consideration to make sure dependencies are fully loaded? http://stackoverflow.com/questions/16423156/getting-requirejs-to-work-with-jasmine – Chris Hawkes Feb 24 '16 at 19:51

1 Answers1

2

Tell Jasmine to run the 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

Marc
  • 1,300
  • 1
  • 10
  • 15