Skip to content

Commit

Permalink
test: avoid errorneous initial render from setRoutes
Browse files Browse the repository at this point in the history
  • Loading branch information
platosha committed Sep 26, 2024
1 parent b838b53 commit bf2ea88
Show file tree
Hide file tree
Showing 4 changed files with 887 additions and 695 deletions.
25 changes: 13 additions & 12 deletions test/router/dynamic-redirect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,43 @@ describe('Vaadin.Router', () => {
let history: sinon.SinonStubbedInstance<History>;

before(() => {
history = sinon.createStubInstance(History);
outlet = document.createElement('div');
document.body.append(outlet);
});

after(() => {
Object.values(history).forEach((stub: sinon.SinonStub) => stub.restore());
outlet.remove();
});

beforeEach(() => {
cleanup(outlet);
history = sinon.createStubInstance(History);

// create a new router instance
router = new Router(outlet);
});

afterEach(() => {
Object.values(history).forEach((stub: sinon.SinonStub) => stub.resetHistory());
cleanup(outlet);
router.unsubscribe();
});

describe('resolver chain and router features', () => {
it('redirect overwrites activated routes', async () => {
await router.setRoutes([
{ path: '/a', children: [{ path: '/b', children: [{ path: '/c', component: 'x-home-view' }] }] },
{ path: '/', redirect: '/a/b/c' },
]);
await router.setRoutes(
[
{ path: '/a', children: [{ path: '/b', children: [{ path: '/c', component: 'x-home-view' }] }] },
{ path: '/', redirect: '/a/b/c' },
],
true,
);

await router.render('/');

verifyActiveRoutes(router, ['/a', '/b', '/c']);
});

it('action that returns custom component activates route', async () => {
await router.setRoutes([{ path: '/', action: (_context, commands) => commands?.component('x-home-view') }]);
await router.setRoutes([{ path: '/', action: (_context, commands) => commands?.component('x-home-view') }], true);

await router.render('/');

Expand All @@ -64,7 +65,7 @@ describe('Vaadin.Router', () => {
await router.setRoutes([
{ path: '/', action: (_context, commands) => commands?.redirect('/a') },
{ path: '/a', component: 'x-users-view' },
]);
], true);

await router.render('/');

Expand All @@ -79,7 +80,7 @@ describe('Vaadin.Router', () => {
{ path: '/', action: (_context, commands) => commands?.redirect('/u') },
{ path: '/u', action: (_context, commands) => commands?.redirect('/users') },
{ path: '/users', component: 'x-users-list' },
]);
], true);

await router.render('/');

Expand All @@ -94,7 +95,7 @@ describe('Vaadin.Router', () => {
{ path: '/a', action: (_context, commands) => commands?.redirect('/b') },
{ path: '/b', action: (_context, commands) => commands?.redirect('/c') },
{ path: '/c', action: (_context, commands) => commands?.redirect('/a') },
]);
], true);

const onError = sinon.spy();
// eslint-disable-next-line @typescript-eslint/use-unknown-in-catch-callback-variable
Expand Down
Loading

0 comments on commit bf2ea88

Please sign in to comment.