在Angular 2.0.0中,我正在對使用Router的組件進行單元測試。但是,我得到'提供的參數不匹配調用目標的任何簽名'。錯誤。在spec.ts的Visual Studio代碼中,它是以紅色突出顯示的新路由器()Angular 2 - 使用路由器進行單元測試
我真的很感激,如果有人能讓我知道正確的語法是什麼嗎?提前致謝。我的代碼如下:
spec.ts
import { TestBed, async } from '@angular/core/testing';
import { NavToolComponent } from './nav-tool.component';
import { ComponentComm } from '../../shared/component-comm.service';
import { Router } from '@angular/router';
describe('Component: NavTool',() => {
it('should create an instance',() => {
let component = new NavToolComponent(new ComponentComm(), new Router());
expect(component).toBeTruthy();
});
});
組件構造
constructor(private componentComm: ComponentComm, private router: Router) {}
謝謝,這個作品!我還使用'router = TestBed.get(Router)'並將路由器保存到燈具旁邊的變量中,而不是將組件轉換爲任何形式,正如https://angular.io/guide/testing#testbedget中所推薦的那樣 –
謝謝你 - 它的工作原理:) – ICantSeeSharp
謝謝,這解決了我的問題:無法讀取嘲弄路由器時未定義的屬性「根」。 –