Skip to content

Commit 7af2eff

Browse files
refactor: improve schema (#257)
1 parent 98412f9 commit 7af2eff

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

src/options.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"type": "array",
99
"items": {
1010
"type": "string"
11-
}
11+
},
12+
"minItems": 1,
13+
"uniqueItems": true
1214
},
1315
{
1416
"type": "object",
@@ -17,7 +19,9 @@
1719
"type": "array",
1820
"items": {
1921
"type": "string"
20-
}
22+
},
23+
"minItems": 1,
24+
"uniqueItems": true
2125
},
2226
"filter": {
2327
"instanceof": "Function"

test/__snapshots__/validate-options.test.js.snap

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`validate options should throw an error on the "attributes" option with "[":src",":src"]" value 1`] = `
4+
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
5+
- options.attributes should not contain the item ':src' twice."
6+
`;
7+
8+
exports[`validate options should throw an error on the "attributes" option with "[]" value 1`] = `
9+
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
10+
- options.attributes should be an non-empty array."
11+
`;
12+
13+
exports[`validate options should throw an error on the "attributes" option with "{"filter":false}" value 1`] = `
14+
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
15+
- options.attributes.filter should be an instance of function."
16+
`;
17+
18+
exports[`validate options should throw an error on the "attributes" option with "{"list":[":src",":src"]}" value 1`] = `
19+
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
20+
- options.attributes.list should not contain the item ':src' twice."
21+
`;
22+
23+
exports[`validate options should throw an error on the "attributes" option with "{"list":[]}" value 1`] = `
24+
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
25+
- options.attributes.list should be an non-empty array."
26+
`;
27+
28+
exports[`validate options should throw an error on the "attributes" option with "{"root":false}" value 1`] = `
29+
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
30+
- options.attributes.root should be a string."
31+
`;
32+
333
exports[`validate options should throw an error on the "attributes" option with "true" value 1`] = `
434
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
535
- options.attributes should be one of these:
6-
boolean | [string, ...] | object { root?, list? }
36+
boolean | [string, ...] (should not have fewer than 1 item, should not have duplicate items) | object { list?, filter?, root? }
737
Details:
838
* options.attributes should be a boolean.
939
* options.attributes should be an array:
10-
[string, ...]
40+
[string, ...] (should not have fewer than 1 item, should not have duplicate items)
1141
* options.attributes should be an object:
12-
object { root?, list? }"
42+
object { list?, filter?, root? }"
1343
`;
1444
1545
exports[`validate options should throw an error on the "esModule" option with "true" value 1`] = `

test/validate-options.test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ describe('validate options', () => {
66
success: [
77
true,
88
false,
9-
[],
109
['img:src'],
1110
['img:src', ':srcset'],
1211
{ root: '.' },
@@ -16,7 +15,15 @@ describe('validate options', () => {
1615
{ list: ['img:src'], root: '.' },
1716
{ list: ['img:src'], root: '.', filter: () => true },
1817
],
19-
failure: ['true'],
18+
failure: [
19+
'true',
20+
[],
21+
[':src', ':src'],
22+
{ list: [] },
23+
{ list: [':src', ':src'] },
24+
{ filter: false },
25+
{ root: false },
26+
],
2027
},
2128
esModule: {
2229
success: [true, false],

0 commit comments

Comments
 (0)