Angular 2 birim testi yazıyorum. Bileşen başlatıldıktan sonra tanımam gereken bir @ViewChild
alt bileşen var. Bu durumda, ng2-bootstrap kitaplığından gelen Timepicker
bileşenidir, ancak özelliklerin önemi olmamalıdır. 'dan sonra alt bileşen örneği hala tanımlanmamış.Açısal 2 birim testi - @ViewChild tanımlanmamış
Sözde kod:
sözde kod konsolu günlüğü ulaşana kadar beklendiği gibi çalışır@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
tanımsızdır. Bu neden oluyor?
Yanıt buldunuz mu? Aynı problemim var. – user3495469