Skip to content

Instantly share code, notes, and snippets.

@t-palmer
Created March 9, 2019 12:36
Show Gist options
  • Save t-palmer/329548ba36d2011e885e828da1b27c0a to your computer and use it in GitHub Desktop.
Save t-palmer/329548ba36d2011e885e828da1b27c0a to your computer and use it in GitHub Desktop.
Example spec file for parent component for viewchild-unit-test-example
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ParentComponent } from './parent.component';
import { ChildComponent } from '../child/child.component';
describe('ParentComponent', () => {
let component: ParentComponent;
let fixture: ComponentFixture<ParentComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ParentComponent,
ChildComponent
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ParentComponent);
component = fixture.componentInstance;
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