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 365794f
Show file tree
Hide file tree
Showing 2 changed files with 51 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
35 changes: 35 additions & 0 deletions packages/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,41 @@ describe('Integration', () => {
expect(navigation.extras.state).toEqual(state);
})));

it('should set history.state when navigation with browser go',
fakeAsync(inject([Router, Location], (router: Router, location: SpyLocation) => {
router.resetConfig([
{path: '', component: SimpleCmp},
{path: 'simple', component: SimpleCmp},
]);

const fixture = createRoot(router, RootCmp);
let navigation: Navigation = null!;
router.events.subscribe(e => {
if (e instanceof NavigationStart) {
navigation = <Navigation>router.getCurrentNavigation()!;
}
});

const state = {foo: 'bar'};
router.navigateByUrl('/simple', {state});
tick();
location.goTo(-1);
tick();
location.goTo(1);
tick();
location.goTo(-100);
tick();
location.goTo(100);
tick();
location.goTo(0);
tick();
location.goTo();
tick();

expect(navigation.extras.state).toBeDefined();
expect(navigation.extras.state).toEqual(state);
})));

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 365794f

Please sign in to comment.