2016-07-26 42 views
4

我正在使用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(); 
}); 
}); 

但是,如果我沒有構造參數構建一切工作正常。如果在構建之後添加此參數,則一切正常。

我缺少什麼?

回答

1

看看這一行let component = new NotificationsComponent();

當您爲NotificationsComponent創建新對象時,您未提供參數,而其構造函數需要類型爲ElementRef的對象。

這就是爲什麼你沒有構造參數構建一切正常。

+0

我注意到,但我試圖提供一個參數,但任何不工作!你有什麼建議? –

+0

如果您的'NotificationsComponent'不需要'ElementRef',只需將它從構造函數中移除即可。否則,你可能想要檢查你正在使用哪個測試框架,併爲它提供一個存根。 –

+0

我可以刪除,但我想知道如何解決它! –

0

嗨兄弟好,有一個臨時解決這個問題,因爲我陷入了同樣的問題,沒有人還不能解釋如何以及發生了什麼,但你可以嘗試進入notification.component.ts並更改構造函數到:「構造函數(私人_elRef:任何= ElementRef){}」 重新加載然後改回它是什麼

+0

嘿夥計,tks分享這個想法!但是,它仍然是錯誤的。 zone.js:463錯誤:未捕獲(承諾中):錯誤:錯誤:無法解析NotificationsComponent的所有參數:(?)。(...)。 我已經評論了notifications.components.spec.ts中的所有代碼暫時! –

相關問題