Skip to content

Instantly share code, notes, and snippets.

@AlexLakatos
Forked from gsans/router.spec.ts
Created July 21, 2017 11:14
Show Gist options
  • Save AlexLakatos/5a338b653e5b4be3e8f5d7e83434e4bf to your computer and use it in GitHub Desktop.
Save AlexLakatos/5a338b653e5b4be3e8f5d7e83434e4bf to your computer and use it in GitHub Desktop.
router.spec.ts
describe('Router tests', () => {
//setup
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
RouterTestingModule.withRoutes(routes),
AppModule
]
});
});
//specs
it('can navigate to home (async)', async(() => {
let fixture = TestBed.createComponent(TestComponent);
TestBed.get(Router)
.navigate(['/home'])
.then(() => {
expect(location.pathname.endsWith('/home')).toBe(true);
}).catch(e => console.log(e));
}));
it('can navigate to home (fakeAsync/tick)', fakeAsync(() => {
let fixture = TestBed.createComponent(TestComponent);
TestBed.get(Router).navigate(['/home']);
fixture.detectChanges();
//execute all pending asynchronous calls
tick();
expect(location.pathname.endsWith('/home')).toBe(true);
}));
it('can navigate to home (done)', done => {
let fixture = TestBed.createComponent(TestComponent);
TestBed.get(Router)
.navigate(['/home'])
.then(() => {
expect(location.pathname.endsWith('/home')).toBe(true);
done();
}).catch(e => console.log(e));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment