我正在尝试测试我的路由解析器,并且在测试时我得到了TypeError:ctor不是构造函数,也不知道为什么它会发生,而typescript编译时没有错误。
TypeError: ctor is not a constructor
TypeError: ctor is not a constructor
at _createClass (http://localhost:9877/_karma_webpack_/vendor.bundle.js:42355:26)
at _createProviderInstance$1 (http://localhost:9877/_karma_webpack_/vendor.bundle.js:42330:26)
at resolveNgModuleDep (http://localhost:9877/_karma_webpack_/vendor.bundle.js:42315:17)
at _createClass (http://localhost:9877/_karma_webpack_/vendor.bundle.js:42362:26)
at _createProviderInstance$1 (http://localhost:9877/_karma_webpack_/vendor.bundle.js:42330:26)
at resolveNgModuleDep (http://localhost:9877/_karma_webpack_/vendor.bundle.js:42315:17)
at NgModuleRef_.webpackJsonp../node_modules/@angular/core/@angular/core.es5.js.NgModuleRef_.get (http://localhost:9877/_karma_webpack_/vendor.bundle.js:43401:16)
at Testbed.webpackJsonp../node_modules/@angular/core/@angular/core/testing.es5.js.Testbed.get (http://localhost:9877/_karma_webpack_/vendor.bundle.js:48412:47)
at http://localhost:9877/_karma_webpack_/vendor.bundle.js:48418:61
at Array.map (native)
这可能是提供者声明中的错误。
当您尝试模拟提供程序并使用useClass而不是useValue时,会触发错误“TypeError:ctor不是构造函数”。
这是一个触发错误的示例:
providers: [{provide: OrderService,useClass: new OrderServiceMock()}]
正确的声明是:
providers: [{provide: OrderService,useValue: new OrderServiceMock()}]