각도 2 단위 테스트를 쓰고 있습니다. 구성 요소를 초기화 한 후 인식해야하는 @ViewChild
하위 구성 요소가 있습니다. 이 경우 ng2-bootstrap 라이브러리의 구성 요소는 Timepicker
이지만 세부 사항은 중요하지 않습니다. 이후 detectChanges()
하위 구성 요소 인스턴스가 아직 정의되지 않았습니다.각도 2 단위 테스트 - @ViewChild가 정의되지 않았습니다.
의사 코드 :
의사 코드는 콘솔 로그에 도달 할 때까지 예상대로 작동@Component({
template: `
<form>
<timepicker
#timepickerChild
[(ngModel)]="myDate">
</timepicker>
</form>
`
})
export class ExampleComponent implements OnInit {
@ViewChild('timepickerChild') timepickerChild: TimepickerComponent;
public myDate = new Date();
}
// Spec
describe('Example Test',() => {
let exampleComponent: ExampleComponent;
let fixture: ComponentFixture<ExampleComponent>;
beforeEach(() => {
TestBed.configureTestingModel({
// ... whatever needs to be configured
});
fixture = TestBed.createComponent(ExampleComponent);
});
it('should recognize a timepicker'. async(() => {
fixture.detectChanges();
const timepickerChild: Timepicker = fixture.componentInstance.timepickerChild;
console.log('timepickerChild', timepickerChild)
}));
});
. timepickerChild
은 정의되지 않습니다. 왜 이런 일이 일어나는 걸까요?
답변을 찾았습니까? 나는 같은 문제를 가지고있다. – user3495469