Created
March 9, 2019 22:28
-
-
Save t-palmer/073f44993e3244627ae7aecd14c43a42 to your computer and use it in GitHub Desktop.
Example spec file for parent component for viewchild-unit-test-example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |
import { ParentComponent } from './parent.component'; | |
import { ChildComponent } from '../child/child.component'; | |
import { ChildStubComponent } from '../child/child-stub.component.spec'; | |
describe('ParentComponent', () => { | |
let component: ParentComponent; | |
let fixture: ComponentFixture<ParentComponent>; | |
beforeEach(async(() => { | |
TestBed.configureTestingModule({ | |
declarations: [ | |
ParentComponent, | |
ChildStubComponent | |
] | |
}) | |
.compileComponents(); | |
})); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(ParentComponent); | |
component = fixture.componentInstance; | |
component.childComponent = TestBed.createComponent(ChildStubComponent).componentInstance as ChildComponent; | |
fixture.detectChanges(); | |
}); | |
it('should create', () => { | |
expect(component).toBeTruthy(); | |
}); | |
it('should call updateTimeStamp', () => { | |
spyOn(component.childComponent, 'updateTimeStamp'); | |
component.update(); | |
expect(component.childComponent.updateTimeStamp).toHaveBeenCalled(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment