gpt4 book ai didi

Angular 4单元测试错误 `TypeError: ctor is not a constructor`

转载 作者:太空狗 更新时间:2023-10-29 16:45:57 30 4
gpt4 key购买 nike

我正在尝试测试我的路由解析器,在测试时我得到了 TypeError: ctor is not a constructor 并且不知道为什么在 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 is not a constructor”。

这是一个引发错误的例子:

providers: [{provide: OrderService, useClass: new OrderServiceMock()}]

正确的声明是:

providers: [{provide: OrderService, useValue: new OrderServiceMock()}]

关于 Angular 4单元测试错误 `TypeError: ctor is not a constructor`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44597532/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com