From e452c2b03ec7da7281724be4995b2b3cb9b0c4c9 Mon Sep 17 00:00:00 2001 From: carlosmaniero Date: Sat, 18 Jul 2020 12:25:14 -0300 Subject: [PATCH] ensure that history.push called after a url change works --- jig/framework/router/__tests__/history.spec.ts | 16 ++++++++++++++++ jig/framework/router/history.ts | 4 ++-- jig/package.json | 2 +- jigcss/package.json | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/jig/framework/router/__tests__/history.spec.ts b/jig/framework/router/__tests__/history.spec.ts index 061b715..24997c7 100644 --- a/jig/framework/router/__tests__/history.spec.ts +++ b/jig/framework/router/__tests__/history.spec.ts @@ -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'); + }); + }); }); }); diff --git a/jig/framework/router/history.ts b/jig/framework/router/history.ts index 0e9b1bb..b29875d 100644 --- a/jig/framework/router/history.ts +++ b/jig/framework/router/history.ts @@ -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(); @@ -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 { diff --git a/jig/package.json b/jig/package.json index 8082800..79f960e 100644 --- a/jig/package.json +++ b/jig/package.json @@ -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": { diff --git a/jigcss/package.json b/jigcss/package.json index 0797c62..7db9c7d 100644 --- a/jigcss/package.json +++ b/jigcss/package.json @@ -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",