Angular 2提供的参数不匹配调用目标的任何签名(spec.ts)
我正在使用Angular2 Cli构建Angular2应用程序。 我有角产生一个具有这样Angular 2提供的参数不匹配调用目标的任何签名(spec.ts)
constructor(private _elRef: ElementRef) {}
构造当我建(NPM开始)我得到这个错误
...angular2/tmp/broccoli_type_script_compiler-input_base_path-wKrIZXNv.tmp/0/src/app/notifications/notifications.component.spec.ts (10, 21): Supplied parameters do not match any signature of call target
文件notifications.component.spec.ts一个notifications.component cli是这样的
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { addProviders, async, inject } from '@angular/core/testing';
import { NotificationsComponent } from './notifications.component';
describe('Component: Notifications',() => {
it('should create an instance',() => {
let component = new NotificationsComponent();
expect(component).toBeTruthy();
});
});
但是,如果我没有构造参数构建一切工作正常。如果在构建之后添加此参数,则一切正常。
我缺少什么?
看看这一行let component = new NotificationsComponent();
。
当您为NotificationsComponent
创建新对象时,您未提供参数,而其构造函数需要类型为ElementRef
的对象。
这就是为什么你没有构造参数构建一切正常。
嗨兄弟好,有一个临时解决这个问题,因为我陷入了同样的问题,没有人还不能解释如何以及发生了什么,但你可以尝试进入notification.component.ts并更改构造函数到:“构造函数(私人_elRef:任何= ElementRef){}” 重新加载然后改回它是什么
嘿伙计,tks分享这个想法!但是,它仍然是错误的。 zone.js:463错误:未捕获(承诺中):错误:错误:无法解析NotificationsComponent的所有参数:(?)。(...)。 我已经评论了notifications.components.spec.ts中的所有代码暂时! –
我注意到,但我试图提供一个参数,但任何不工作!你有什么建议? –
如果您的'NotificationsComponent'不需要'ElementRef',只需将它从构造函数中移除即可。否则,你可能想要检查你正在使用哪个测试框架,并为它提供一个存根。 –
我可以删除,但我想知道如何解决它! –