Dependency inside a subcomponent not getting instantiated during unit test

I have a parent component with a child:


selector: 'parent'



In both the parent and child I have a service that provides an observable that both are subscribed to:

parent.ts & child.ts

constructor(private service: Service){}
ngOnInit() {

And finally, I have a unit test for the parent component:

beforeEach(async () => {
    await TestBed.configureTestingModule({
        declarations: [ParentComponent],
        imports: [
        providers: [Service],

beforeEach(() => {
    fixture = TestBed.createComponent(ParentComponent);
    component = fixture.componentInstance;


it('should create page properly', () => {
    component.prop = prop; // prop is defined elsewhere; not really relevant
    fixture.detectChanges(); // <-- failing here

I'm getting the error: Cannot read property 'method' of undefined. The stack trace refers to the service in the child component. And as I understand it, the error is from the instantiation of the child component. How would I provide the service to the child in this case?


How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum