Skip to content

Commit 1601039

Browse files
committed
update tests
1 parent 8b54b85 commit 1601039

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

router.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ export const exec = (url, route, matches) => {
4545
// normal/optional field:
4646
else if (val) val = decodeURIComponent(val);
4747
matches.params[param] = val;
48-
if (param != 'ref' && param != 'key' && param != 'path' && param != 'query' && param != 'params') matches[param] = val;
48+
if (param != 'ref' && param != 'key' && param != 'path' && param != 'query' && param != 'params') {
49+
matches[param] = val;
50+
}
4951
if (rest) break;
5052
}
5153
return matches;

test/match.test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ describe('match', () => {
1515

1616
it('Param route', () => {
1717
const accurateResult = doExec('/user/2', '/user/:id');
18-
expect(accurateResult).toEqual({ path: '/', params: { id: '2' }, query: {} });
18+
expect(accurateResult).toEqual({ path: '/user/2', params: { id: '2' }, query: {}, id: '2' });
1919

2020
const inaccurateResult = doExec('/', '/user/:id');
2121
expect(inaccurateResult).toEqual(undefined);
2222
});
2323

2424
it('Optional param route', () => {
2525
const accurateResult = doExec('/user', '/user/:id?');
26-
expect(accurateResult).toEqual({ path: '/', params: { id: undefined }, query: {} });
26+
expect(accurateResult).toEqual({ path: '/user', params: { id: undefined }, query: {} });
2727

2828
const inaccurateResult = doExec('/', '/user/:id?');
2929
expect(inaccurateResult).toEqual(undefined);
@@ -37,7 +37,9 @@ describe('match', () => {
3737
seg2: '_SEGMENT2_'
3838
},
3939
path: '/about-late/_SEGMENT1_/_SEGMENT2_/',
40-
query: {}
40+
query: {},
41+
seg1: '_SEGMENT1_',
42+
seg2: '_SEGMENT2_'
4143
});
4244
});
4345

test/router.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ describe('Router', () => {
8282
expect(Home).not.toHaveBeenCalled();
8383
expect(Profiles).not.toHaveBeenCalled();
8484
expect(Profile).toHaveBeenCalledWith(
85-
{ path: '/profiles/bob', query: {}, params: { id: 'bob' } },
85+
{ path: '/profiles/bob', query: {}, params: { id: 'bob' }, id: 'bob' },
8686
expect.anything()
8787
);
8888
expect(Fallback).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)