-
-
Notifications
You must be signed in to change notification settings - Fork 449
/
properties.js
41 lines (38 loc) · 1.2 KB
/
properties.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import deepEqual from 'deep-equal';
import fastCheck from 'fast-check';
import test from 'ava';
import queryString from '../index.js';
// 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 queryParametersArbitrary = fastCheck.dictionary(
fastCheck.fullUnicodeString(1, 10),
fastCheck.oneof(
fastCheck.fullUnicodeString(),
fastCheck.constant(null),
fastCheck.array(fastCheck.oneof(fastCheck.fullUnicodeString(), fastCheck.constant(null)), 2, 10),
),
);
const optionsArbitrary = fastCheck.record({
arrayFormat: fastCheck.constantFrom('bracket', 'index', 'none'),
strict: fastCheck.boolean(),
encode: fastCheck.constant(true),
sort: fastCheck.constant(false),
}, {withDeletedKeys: true});
test.failing('should read correctly from stringified query parameters', t => {
t.notThrows(() => {
fastCheck.assert(
fastCheck.property(
queryParametersArbitrary,
optionsArbitrary,
(object, options) => deepEqual(queryString.parse(queryString.stringify(object, options), options), object),
),
{
verbose: true,
},
);
});
});