Skip to content

Commit

Permalink
test(common): add more tests for location_spec and integration spec
Browse files Browse the repository at this point in the history
Add more tests for location_spec to test location.goTo(0), location.goTo(),
location.goTo(100) and location.goTo(-100). We also add new tests for
integration spec.
  • Loading branch information
aahmedayed committed Sep 18, 2020
1 parent 8e474e7 commit 16819c8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/common/test/location/location_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ describe('Location Class', () => {

location.goTo(2);
expect(location.getState()).toEqual({url: 'test3'});

location.go('/test3', '', {url: 'test4'});
location.goTo(0);
expect(location.getState()).toEqual({url: 'test4'});

location.goTo();
expect(location.getState()).toEqual({url: 'test4'});

location.goTo(100);
expect(location.getState()).toEqual({url: 'test4'});

location.goTo(-100);
expect(location.getState()).toEqual({url: 'test4'});

location.back();
expect(location.getState()).toEqual({url: 'test3'});
});
});

Expand Down
41 changes: 41 additions & 0 deletions packages/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,47 @@ describe('Integration', () => {
expect(navigation.extras.state).toEqual(state);
})));

it('should navigate correctly when using `Location#goTo',
fakeAsync(inject([Router, Location], (router: Router, location: SpyLocation) => {
router.resetConfig([
{path: 'first', component: SimpleCmp},
{path: 'second', component: SimpleCmp},

]);

createRoot(router, RootCmp);

router.navigateByUrl('/first');
tick();
router.navigateByUrl('/second');
tick();
expect(router.url).toEqual('/second');

location.goTo(-1);
tick();
expect(router.url).toEqual('/first');

location.goTo(1);
tick();
expect(router.url).toEqual('/second');

location.goTo(-100);
tick();
expect(router.url).toEqual('/second');

location.goTo(100);
tick();
expect(router.url).toEqual('/second');

location.goTo(0);
tick();
expect(router.url).toEqual('/second');

location.goTo();
tick();
expect(router.url).toEqual('/second');
})));

it('should not error if state is not {[key: string]: any}',
fakeAsync(inject([Router, Location], (router: Router, location: SpyLocation) => {
router.resetConfig([
Expand Down

0 comments on commit 16819c8

Please sign in to comment.