From c90997ba62db84d5160ce20231fef4cf8181d385 Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Mon, 27 Jan 2025 10:21:43 +0100 Subject: [PATCH] router: make tests async and properly await results --- packages/app-shell/test/unit.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/app-shell/test/unit.js b/packages/app-shell/test/unit.js index c809e3e5..b163fc35 100644 --- a/packages/app-shell/test/unit.js +++ b/packages/app-shell/test/unit.js @@ -3,31 +3,42 @@ import {assert} from 'chai'; import {Router} from '../src/router.js'; suite('router', () => { - test('basics', () => { + test('basics', async () => { const routes = [ { name: 'foo', path: '', action: (context) => { - return {}; + return {bar: false}; + }, + }, + { + name: 'bar', + path: '/bar', + action: (context) => { + return {bar: true}; }, }, ]; + let myState = {}; const router = new Router(routes, { routeName: 'foo', getState: () => { - return {}; + return myState; + }, + setState: (state) => { + myState = state; }, - setState: (state) => {}, getDefaultState: () => { return {}; }, }); - router.setStateFromCurrentLocation(); - router.update(); - router.updateFromUrl('/?foo=bar#quux'); + await router.setStateFromCurrentLocation(); + await router.update(); + await router.updateFromUrl('/bar?foo=bar#quux'); + assert.equal(myState.bar, true); assert.equal(router.getPathname(), '/'); }); });