2017-12-04 4 views
0

처음으로 각도 2 테스트를 시도하고 있습니다.각도 2 테스트에서 DegugElement가 정의되지 않았습니다.

let component: AlertButtonComponent; 
    let fixture: ComponentFixture<AlertButtonComponent>; 
    let de:DebugElement; 

    it('should have an H1 tag of `Alert Button`' ,() => { 
    console.log('debug element',de) 
    expect(de.query(By.css('h1')).nativeElement.innerText).toBe('lert Button') 
    }) 

나는 또한 오류 typeError: Cannot read property 'query' of undefined을 얻고있다 undefined입니다.

여기

답변

0

확인 도와주세요 : https://angular.io/guide/testing - 당신이 구성 요소 BannerComponent을 테스트하는 경우, 다음과 같이 설정할 필요가 각 웹 사이트에 검사 각도

에서 테스트를, ID는 당신의 설정의 종류를 표시 해달라고 코드

let comp: BannerComponent; 
    let fixture: ComponentFixture<BannerComponent>; 
    let de:  DebugElement; 
    let el:  HTMLElement; 

    beforeEach(() => { 
    TestBed.configureTestingModule({ 
     declarations: [ BannerComponent ], // declare the test component 
    }); 

fixture = TestBed.createComponent(BannerComponent); 
comp = fixture.componentInstance; // BannerComponent test instance 
// query for the title <h1> by CSS element selector 
de = fixture.debugElement.query(By.css('h1')); 

음 오류가 정의되지 let de:DebugElement; 당신이 초기화 할 필요가 의미 있다고 그것.

let de:DebugElement = new DebugElement(); 

또는 사용중인 경우 서비스 참조를 전달해야합니다.

+0

new DebugElement(); 작동 안됨. – raju

+0

@raju - 각도의 링크를 확인하십시오. 일부 정보를 놓친 링크를 확인하고 여기에 내용을 포함하십시오. –

+0

@raju -이 라인 고정 장치를 놓친 지점 = TestBed.createComponent (BannerComponent);는 –

관련 문제