Last active
July 21, 2017 11:31
-
-
Save gsans/3342a01f84adfb4b5f05f8cf713666b7 to your computer and use it in GitHub Desktop.
router.spec.ts
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
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