-
-
Notifications
You must be signed in to change notification settings - Fork 455
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stringify for bracket mode with arrays containing null (#138)
- Loading branch information
1 parent
3bcd4e8
commit e5a6c1f
Showing
5 changed files
with
54 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,8 @@ | |
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"deep-equal": "^1.0.1", | ||
"fast-check": "^0.0.13", | ||
"xo": "*" | ||
} | ||
} |
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,33 @@ | ||
import deepEqual from 'deep-equal'; | ||
import * as fc from 'fast-check'; | ||
import test from 'ava'; | ||
import m from '..'; | ||
|
||
// Valid query parameters must follow: | ||
// - key can be any unicode string (not empty) | ||
// - value must be one of: | ||
// --> any unicode string | ||
// --> null | ||
// --> array containing values defined above (at least two items) | ||
const queryParamsArbitrary = fc.object({ | ||
key: fc.fullUnicodeString(1, 10), | ||
values: [ | ||
fc.fullUnicodeString(), | ||
fc.constant(null), | ||
fc.array(fc.oneof(fc.fullUnicodeString(), fc.constant(null))).filter(a => a.length >= 2) | ||
], | ||
maxDepth: 0 | ||
}); | ||
|
||
const optionsArbitrary = fc.record({ | ||
arrayFormat: fc.constantFrom('bracket', 'index', 'none'), | ||
strict: fc.boolean(), | ||
encode: fc.boolean(), | ||
sort: fc.boolean() | ||
}); | ||
|
||
test('should read correctly from stringified query params', t => { | ||
t.notThrows(() => fc.assert( | ||
fc.property(queryParamsArbitrary, optionsArbitrary, | ||
(obj, opts) => deepEqual(m.parse(m.stringify(obj, opts), opts), obj)))); | ||
}); |
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