简体   繁体   English

在angular2 /测试中获得404

[英]Getting a 404 on angular2/testing

I am getting a 404 on angular2/testing as soon as i insert this line into my spec file. 一旦我将此行插入到我的spec文件中,我就会在angular2 /测试中获得404。

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

This is my code inside body tag in user-tests.html 这是我在user-tests.html中的body标签内的代码

  <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 ? 是否还有其他软件包需要安装才能在角度2中进行测试? I have installed Jamsine-core per angular2 docs. 我已经为每个angular2文档安装了Jamsine-core。

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

Thanks ! 谢谢 !

When using SystemJS (as per docs), you need to add the bundles seperately. 使用SystemJS时(根据文档),您需要单独添加捆绑包。 This is necessary for every module : http, router and testing. 这对于每个模块都是必需的:http,路由器和测试。

In your case you need to add testing.dev.js bundle. 在您的情况下,您需要添加testing.dev.js包。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM