-
-
Save AlexLakatos/5a338b653e5b4be3e8f5d7e83434e4bf 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