-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0212ae4
commit 9c9f677
Showing
8 changed files
with
104 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict' | ||
|
||
const t = require('tap') | ||
const test = t.test | ||
const querystring = require('querystring') | ||
const FindMyWay = require('../') | ||
|
||
test('Custom querystring parser', t => { | ||
t.plan(2) | ||
|
||
const findMyWay = FindMyWay({ | ||
querystringParser: function (str) { | ||
t.equal(str, 'foo=bar&baz=faz') | ||
return querystring.parse(str) | ||
} | ||
}) | ||
findMyWay.on('GET', '/', () => {}) | ||
|
||
t.same(findMyWay.find('GET', '/?foo=bar&baz=faz').searchParams, { foo: 'bar', baz: 'faz' }) | ||
}) | ||
|
||
test('Custom querystring parser should be called also if there is nothing to parse', t => { | ||
t.plan(2) | ||
|
||
const findMyWay = FindMyWay({ | ||
querystringParser: function (str) { | ||
t.equal(str, '') | ||
return querystring.parse(str) | ||
} | ||
}) | ||
findMyWay.on('GET', '/', () => {}) | ||
|
||
t.same(findMyWay.find('GET', '/').searchParams, {}) | ||
}) | ||
|
||
test('Querystring without value', t => { | ||
t.plan(2) | ||
|
||
const findMyWay = FindMyWay({ | ||
querystringParser: function (str) { | ||
t.equal(str, 'foo') | ||
return querystring.parse(str) | ||
} | ||
}) | ||
findMyWay.on('GET', '/', () => {}) | ||
t.same(findMyWay.find('GET', '/?foo').searchParams, { foo: '' }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters