Getting a 404 on angular2/testing

瘦欲@ 提交于 2019-12-11 13:53:53

问题


I am getting a 404 on angular2/testing as soon as i insert this line into my spec file.

import {
    iit,
    it,
    inject,
    injectAsync,
    beforeEachProviders,
    fakeAsync,
    tick
} from 'angular2/testing';

This is my code inside body tag in user-tests.html

  <script src="node_modules/systemjs/dist/system.src.js"></script>
  <script src="node_modules/angular2/bundles/angular2.dev.js"></script>
  <script src="node_modules/angular2/bundles/http.dev.js"></script>
  <script src="node_modules/angular2/bundles/router.dev.js"></script>
  <script>
      System.config({
          packages: {
              'app': {defaultExtension: 'js'}
          }
      });
      System.import('app/components/user.spec')
              .then(window.onload)
              .catch(console.error.bind(console));
  </script>

Is there any other packages to install to enable testing in angular 2 ? I have installed Jamsine-core per angular2 docs.

npm install jasmine-core --save-dev --save-exact

Thanks !


回答1:


When using SystemJS (as per docs), you need to add the bundles seperately. This is necessary for every module : http, router and testing.

In your case you need to add testing.dev.js bundle.

<script src="node_modules/angular2/bundles/angular2-polyfills.src.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/testing.dev.js"></script>


来源:https://stackoverflow.com/questions/34561926/getting-a-404-on-angular2-testing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!