Skip to content

Commit

Permalink
ensure that history.push called after a url change works
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmaniero committed Jul 18, 2020
1 parent 933865c commit e452c2b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
16 changes: 16 additions & 0 deletions jig/framework/router/__tests__/history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,21 @@ describe('history', () => {
expect(history.getCurrentUrl()).toBe('/home');
});
});

it('keeps the latest url when url changes into an observer', async () => {
const dom = configureJSDOM(undefined, 'http://jigjs.com/');
const history = new History(dom.window);

const subscription = observe(history, () => {
subscription.unsubscribe();
history.push('/home');
});

history.push('/hello/world');

await waitForExpect(() => {
expect(dom.window.location.pathname).toBe('/home');
});
});
});
});
4 changes: 2 additions & 2 deletions jig/framework/router/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {JigWindow} from '../../types';
@observable()
export class History {
@observing()
private currentUrl;
private currentUrl: string;

constructor(private readonly window: JigWindow) {
this.updateCurrentUrl();
Expand All @@ -17,8 +17,8 @@ export class History {
}

push(url: string): void {
this.currentUrl = url;
this.window.history.pushState(undefined, undefined, url);
this.currentUrl = url;
}

getCurrentUrl(): string {
Expand Down
2 changes: 1 addition & 1 deletion jig/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jigjs",
"version": "0.0.0-pre-alpha.22",
"version": "0.0.0-pre-alpha.23",
"description": "A front-end library",
"author": "Carlos Maniero",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion jigcss/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jigcss",
"version": "0.0.0-pre-alpha.22",
"version": "0.0.0-pre-alpha.23",
"description": "A css-in-js module for jigjs",
"repository": "https://github.com/carlosmaniero/jigjs.git",
"author": "Carlos Maniero",
Expand Down

0 comments on commit e452c2b

Please sign in to comment.