Skip to content

Instantly share code, notes, and snippets.

@gsans
Last active July 21, 2017 11:07
Show Gist options
  • Save gsans/96a04ac8ccc64a5b9f1bdaa96ee2e848 to your computer and use it in GitHub Desktop.
Save gsans/96a04ac8ccc64a5b9f1bdaa96ee2e848 to your computer and use it in GitHub Desktop.
greeter.spec.ts
describe('Component: Greeter', () => {
let fixture, greeter, element, de;
//setup
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ Greeter ]
});
fixture = TestBed.createComponent(Greeter);
greeter = fixture.componentInstance; // to access properties and methods
element = fixture.nativeElement; // to access DOM element
de = fixture.debugElement; // test helper
});
//specs
it('should render `Hello World!`', async(() => {
greeter.name = 'World';
//trigger change detection
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('h1').innerText).toBe('Hello World!');
expect(de.query(By.css('h1')).nativeElement.innerText).toBe('Hello World!');
});
}));
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment