Skip to content

Commit

Permalink
router: make tests async and properly await results
Browse files Browse the repository at this point in the history
  • Loading branch information
lazka committed Jan 27, 2025
1 parent adf4123 commit c90997b
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions packages/app-shell/test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(), '/');
});
});

0 comments on commit c90997b

Please sign in to comment.