Angular 2 unit testing - @ViewChild is undefined

前端 未结 5 955
情歌与酒
情歌与酒 2021-02-06 20:59

I am writing an Angular 2 unit test. I have a @ViewChild subcomponent that I need to recognize after the component initializes. In this case it\'s a Timepicke

5条回答
  •  再見小時候
    2021-02-06 21:32

    In most cases just add it to declaration and you are good to go.

    beforeEach(async(() => {
            TestBed
                .configureTestingModule({
                    imports: [],
                    declarations: [TimepickerComponent],
                    providers: [],
                })
                .compileComponents() 
    

提交回复
热议问题