2017-02-28 77 views

回答

0

我做了下面的步驟問題固定

1)創建路由器stubs.ts測試文件夾在根文件夾下面的代碼

import { Directive, Input } from '@angular/core'; 

@Directive({ 
    selector: '[routerLink]', 
    host: { 
    '(click)': 'onClick()' 
    } 
}) 
export class RouterLinkStubDirective { 
    @Input('routerLink') linkParams: any; 
    navigatedTo: any = null; 

    onClick() { 
    this.navigatedTo = this.linkParams; 
    } 
} 

2)下面的代碼添加到您的app.component。 spec.ts

import { NO_ERRORS_SCHEMA } from '@angular/core'; 
import { RouterLinkStubDirective } from '../testing/router-stubs'; 

describe('AppComponent',() => { 
    beforeEach(() => { 
    TestBed.configureTestingModule({ 
     declarations: [ AppComponent, RouterLinkStubDirective ], 
     schemas:  [ NO_ERRORS_SCHEMA ] 
    }) 
    .compileComponents() 
    .then(() => { 
     let fixture = TestBed.createComponent(AppComponent); 
     let comp = fixture.componentInstance; 
     // trigger initial data binding 
     fixture.detectChanges(); 
    }); 
    }); 

它固定在錯誤「路由器出口不是已知的元件」

相關問題