Skip to content

Commit

Permalink
chore: update @riadh-adrani/dom-router
Browse files Browse the repository at this point in the history
  • Loading branch information
RiadhAdrani committed Jan 7, 2024
1 parent 9109a2a commit 368de99
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
48 changes: 47 additions & 1 deletion lib/__tests__/router.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { Outlet, createRouter, navigate, unmountRouter } from '../../docs/index.js';
import { RawRoute } from '@riadh-adrani/dom-router';
import { RawRoute, RouterType } from '@riadh-adrani/dom-router';
import { Template } from '@/types.js';
import { __test__mount, __test__unmount } from './utils.js';
import { wait } from '@/helpers/helpers.js';
Expand Down Expand Up @@ -115,3 +115,49 @@ describe('browser router', () => {
expect(document.body.innerHTML).toBe('<div><main><div>ruvy</div></main></div>');
});
});

describe('hash router', () => {
beforeEach(async () => {
createRouter({ routes, type: RouterType.Hash });

await __test__mount(<Outlet />);
});

afterEach(async () => {
unmountRouter();

await __test__unmount();
});

it('should render page correctly (/)', () => {
expect(document.body.innerHTML).toBe('<div><div>Home</div></div>');
});

it('should render page correctly (/users)', async () => {
navigate('/users');

await wait(10);

expect(document.body.innerHTML).toBe(
'<div><div><h1>Users</h1><div>Welcome Users</div></div></div>'
);
});

it('should render page correctly (/users/me)', async () => {
navigate('/users/me');

await wait(10);

expect(document.body.innerHTML).toBe(
'<div><div><h1>Users</h1><div><p>UserId</p><p>Welcome back</p></div></div></div>'
);
});

it('should render page correctly (/editor/ruvy)', async () => {
navigate('/editor/ruvy');

await wait(10);

expect(document.body.innerHTML).toBe('<div><main><div>ruvy</div></main></div>');
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"vitest": "^1.1.0"
},
"dependencies": {
"@riadh-adrani/dom-router": "^0.0.4",
"@riadh-adrani/dom-router": "^0.0.5",
"@riadh-adrani/domer": "^0.0.3",
"@riadh-adrani/obj-utils": "1.0.5",
"@riadh-adrani/type-utils": "1.0.2",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.21.tgz#5de5a2385a35309427f6011992b544514d559aa1"
integrity sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==

"@riadh-adrani/dom-router@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@riadh-adrani/dom-router/-/dom-router-0.0.4.tgz#12578920d3c314fdbbcd7560cfd9085be917ebca"
integrity sha512-GeM1mdjbhZClZeoIyBkyxcg55dkoLmsEe0OmgtpmIAkmI2SUgmusKkDzbHC/tXPzqy+kDe644APyEwd2/Xceog==
"@riadh-adrani/dom-router@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@riadh-adrani/dom-router/-/dom-router-0.0.5.tgz#3177755416c333da7ec6fb622c37ee4289ae2674"
integrity sha512-COaeXiQM1dOeEGKBpcE5CzZhwNljltrO4h1Wvq2VZHyYOMqEzaMFtymJ30WbGY14mkUthMlAerOr32AMYSt53Q==

"@riadh-adrani/domer@^0.0.3":
version "0.0.3"
Expand Down

0 comments on commit 368de99

Please sign in to comment.