Skip to content

Commit 481b46f

Browse files
authored
update tests to pass all required parameters to exec()
1 parent a70f7e5 commit 481b46f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

test/match.test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
import { exec } from '../router.js';
22

3+
function doExec(path, route, opts) {
4+
return exec(path, route, { path, query: {}, params: {}, ...(opts || {}) });
5+
}
6+
37
describe('match', () => {
48
it('Base route', () => {
5-
const accurateResult = exec('/', '/', { path: '/' });
9+
const accurateResult = doExec('/', '/');
610
expect(accurateResult).toEqual({ path: '/', params: {} });
711

8-
const inaccurateResult = exec('/user/1', '/', { path: '/' });
12+
const inaccurateResult = doExec('/user/1', '/');
913
expect(inaccurateResult).toEqual(undefined);
1014
});
1115

1216
it('Param route', () => {
13-
const accurateResult = exec('/user/2', '/user/:id', { path: '/' });
17+
const accurateResult = doExec('/user/2', '/user/:id');
1418
expect(accurateResult).toEqual({ path: '/', params: { id: '2' } });
1519

16-
const inaccurateResult = exec('/', '/user/:id', { path: '/' });
20+
const inaccurateResult = doExec('/', '/user/:id');
1721
expect(inaccurateResult).toEqual(undefined);
1822
});
1923

2024
it('Optional param route', () => {
21-
const accurateResult = exec('/user', '/user/:id?', { path: '/' });
25+
const accurateResult = doExec('/user', '/user/:id?');
2226
expect(accurateResult).toEqual({ path: '/', params: { id: undefined } });
2327

24-
const inaccurateResult = exec('/', '/user/:id?', { path: '/' });
28+
const inaccurateResult = doExec('/', '/user/:id?');
2529
expect(inaccurateResult).toEqual(undefined);
2630
});
2731

2832
it('Handles leading/trailing slashes', () => {
29-
const result = exec('/about-late/_SEGMENT1_/_SEGMENT2_/', '/about-late/:seg1/:seg2/', {});
33+
const result = doExec('/about-late/_SEGMENT1_/_SEGMENT2_/', '/about-late/:seg1/:seg2/');
3034
expect(result).toEqual({
3135
params: {
3236
seg1: '_SEGMENT1_',
@@ -36,7 +40,7 @@ describe('match', () => {
3640
});
3741

3842
it('should not overwrite existing properties', () => {
39-
const result = exec('/foo/bar', '/:path/:query', { path: '/' });
43+
const result = doExec('/foo/bar', '/:path/:query');
4044
expect(result).toEqual({
4145
params: { path: 'foo', query: 'bar' },
4246
path: '/'

0 commit comments

Comments
 (0)