Skip to content

Commit

Permalink
refactor: improve schema (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Mar 16, 2020
1 parent 98412f9 commit 7af2eff
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/options.json
Expand Up @@ -8,7 +8,9 @@
"type": "array",
"items": {
"type": "string"
}
},
"minItems": 1,
"uniqueItems": true
},
{
"type": "object",
Expand All @@ -17,7 +19,9 @@
"type": "array",
"items": {
"type": "string"
}
},
"minItems": 1,
"uniqueItems": true
},
"filter": {
"instanceof": "Function"
Expand Down
36 changes: 33 additions & 3 deletions test/__snapshots__/validate-options.test.js.snap
@@ -1,15 +1,45 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`validate options should throw an error on the "attributes" option with "[":src",":src"]" value 1`] = `
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
- options.attributes should not contain the item ':src' twice."
`;

exports[`validate options should throw an error on the "attributes" option with "[]" value 1`] = `
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
- options.attributes should be an non-empty array."
`;

exports[`validate options should throw an error on the "attributes" option with "{"filter":false}" value 1`] = `
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
- options.attributes.filter should be an instance of function."
`;

exports[`validate options should throw an error on the "attributes" option with "{"list":[":src",":src"]}" value 1`] = `
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
- options.attributes.list should not contain the item ':src' twice."
`;

exports[`validate options should throw an error on the "attributes" option with "{"list":[]}" value 1`] = `
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
- options.attributes.list should be an non-empty array."
`;

exports[`validate options should throw an error on the "attributes" option with "{"root":false}" value 1`] = `
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
- options.attributes.root should be a string."
`;

exports[`validate options should throw an error on the "attributes" option with "true" value 1`] = `
"Invalid options object. HTML Loader has been initialized using an options object that does not match the API schema.
- options.attributes should be one of these:
boolean | [string, ...] | object { root?, list? }
boolean | [string, ...] (should not have fewer than 1 item, should not have duplicate items) | object { list?, filter?, root? }
Details:
* options.attributes should be a boolean.
* options.attributes should be an array:
[string, ...]
[string, ...] (should not have fewer than 1 item, should not have duplicate items)
* options.attributes should be an object:
object { root?, list? }"
object { list?, filter?, root? }"
`;
exports[`validate options should throw an error on the "esModule" option with "true" value 1`] = `
Expand Down
11 changes: 9 additions & 2 deletions test/validate-options.test.js
Expand Up @@ -6,7 +6,6 @@ describe('validate options', () => {
success: [
true,
false,
[],
['img:src'],
['img:src', ':srcset'],
{ root: '.' },
Expand All @@ -16,7 +15,15 @@ describe('validate options', () => {
{ list: ['img:src'], root: '.' },
{ list: ['img:src'], root: '.', filter: () => true },
],
failure: ['true'],
failure: [
'true',
[],
[':src', ':src'],
{ list: [] },
{ list: [':src', ':src'] },
{ filter: false },
{ root: false },
],
},
esModule: {
success: [true, false],
Expand Down

0 comments on commit 7af2eff

Please sign in to comment.