无法在karma配置中导入TestBed

时间:2016-09-04 10:54:05

标签: javascript angular jasmine karma-jasmine

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')?

P.S。

1. npm test

上的错误
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

1 个答案:

答案 0 :(得分:0)

我有角度2.1.2的同样问题。我设法通过降级systemjs版本来修复它。我的systemjs版本是0.19.39,并且在导入@ angular / core / testing时它给出了undefined。当降级到0.19.27时,它可以工作。