【问题标题】:Can't import TestBed in karma config无法在业力配置中导入 TestBed
【发布时间】:2016-09-04 10:54:04
【问题描述】:

Angular 版本 2.0.0-rc.6

karma-test-shim.js (project on github)

Promise.all([
  System.import('@angular/core/testing'),
  System.import('@angular/platform-browser-dynamic/testing')
]).then(function (providers) {
  var coreTesting = providers[0]; //undefined
  var browserTesting = providers[1]; //all right

  coreTesting.TestBed.initTestEnvironment(
    browserTesting.BrowserDynamicTestingModule,
    browserTesting.platformBrowserDynamicTesting());
}).then(function() {
  // Finally, load all spec files.
  // This will run the tests directly.
  return Promise.all(
    allSpecFiles.map(function (moduleName) {
      return System.import(moduleName);
    }));
}).then(__karma__.start, __karma__.error);

实验发现新的/node_modules/@angular/core/testing/index.d.ts 不导出值。

为什么我不能 System.import('@angular/core/testing') 但可以 System.import('@angular/core')?

附言

1.npm 测试

上的错误
PhantomJS 2.1.1 (Linux 0.0.0) ERROR
  {
    "stack": "karma-test-shim.js:72:14\ninvoke@node_modules/zone.js/dist/zone.js:332:34\nrun@node_modules/zone.js/dist/zone.js:225:50\nnode_modules/zone.js/dist/zone.js:591:61\ninvokeTask@node_modules/zone.js/dist/zone.js:365:43\nrunTask@node_modules/zone.js/dist/zone.js:265:58\ndrainMicroTaskQueue@node_modules/zone.js/dist/zone.js:497:43\nrun@node_modules/core-js/client/core.js:4019:30\nnode_modules/core-js/client/core.js:4032:32\nflush@node_modules/core-js/client/core.js:4387:12",
    "line": 72,
    "sourceURL": "karma-test-shim.js"
  }
  1. this bug on github

【问题讨论】:

  • SystemJS 或网络没有错误吗?您如何在 SystemJS 配置中定义它?请注意,对于 UMD 捆绑包,有 a separate file for testing
  • @estus,错误被添加得更高。我在这个project 中没有看到任何与捆绑包相关的配置选项,我以它为例,我应该添加它们吗?如何? My project page

标签: javascript angular jasmine karma-jasmine


【解决方案1】:

我在使用 Angular 2.1.2 时遇到了同样的问题。我设法通过降级 systemjs 版本来修复它。我的 systemjs 版本是 0.19.39,因此在导入 @angular/core/testing 时它给出了 undefined。降级到 0.19.27 时它起作用了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多