Most likely you are calling fixture.detectChanges
before you are setting component.data
it('populated data should do things and stuff', () => {
// create your component, hopefully in the beforeEach
const fixture = TestBed.createComponent(AppComponent);
const component = fixture.componentInstance;
// set the input BEFORE you call fixture.detectChanges the first time
const data = {};
component.data = data
fixture.detectChanges(); // ngOnInit now fires
// assert what you expect to happen
});
Test made as simple as possible. I'd prefer the approach where you use a fake TestHost that can pass the input to your component like it would when running. Here is the documentation around that. I gave an example answer here