Skip to content

Commit

Permalink
test: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Jun 7, 2023
1 parent d0bebec commit 1a88581
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
4 changes: 1 addition & 3 deletions declarations/keywords/absolutePath.d.ts
Expand Up @@ -2,9 +2,7 @@ export default addAbsolutePathKeyword;
export type Ajv = import("ajv").default;
export type SchemaValidateFunction = import("ajv").SchemaValidateFunction;
export type AnySchemaObject = import("ajv").AnySchemaObject;
/** @typedef {import("ajv").default} Ajv */
/** @typedef {import("ajv").SchemaValidateFunction} SchemaValidateFunction */
/** @typedef {import("ajv").AnySchemaObject} AnySchemaObject */
export type SchemaUtilErrorObject = import("../validate").SchemaUtilErrorObject;
/**
*
* @param {Ajv} ajv
Expand Down
2 changes: 2 additions & 0 deletions declarations/validate.d.ts
Expand Up @@ -8,6 +8,7 @@ export type Extend = {
formatExclusiveMinimum?: string | undefined;
formatExclusiveMaximum?: string | undefined;
link?: string | undefined;
allowUndefined?: boolean | undefined;
};
export type Schema = (JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend;
export type SchemaUtilErrorObject = ErrorObject & {
Expand All @@ -33,6 +34,7 @@ export type ValidationErrorConfiguration = {
* @property {string=} formatExclusiveMinimum
* @property {string=} formatExclusiveMaximum
* @property {string=} link
* @property {boolean=} allowUndefined
*/
/** @typedef {(JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend} Schema */
/** @typedef {ErrorObject & { children?: Array<ErrorObject>}} SchemaUtilErrorObject */
Expand Down
7 changes: 1 addition & 6 deletions src/keywords/allowUndefined.js
Expand Up @@ -15,12 +15,7 @@ function addAllowUndefinedKeyword(ajv) {
modifying: true,
/** @type {SchemaValidateFunction} */
validate(kwVal, data, metadata, dataCxt) {
if (
kwVal &&
dataCxt &&
dataCxt.parentData &&
typeof dataCxt.parentDataProperty === "number"
) {
if (kwVal && dataCxt) {
const idx = dataCxt.parentDataProperty;

if (typeof dataCxt.parentData[idx] === "undefined") {
Expand Down
22 changes: 16 additions & 6 deletions test/__snapshots__/index.test.js.snap

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions test/fixtures/schema.json
Expand Up @@ -3811,6 +3811,22 @@
}
]
}
},
"arrayStringAndEnumAndNoUndefined": {
"description": "References to other configurations to depend on.",
"type": "array",
"items": {
"anyOf": [
{
"allowUndefined": false,
"enum": [ 0, false, "", null ]
},
{
"type": "string",
"minLength": 1
}
]
}
}
}
}
8 changes: 8 additions & 0 deletions test/index.test.js
Expand Up @@ -3026,4 +3026,12 @@ describe("Validation", () => {
},
(msg) => expect(msg).toMatchSnapshot()
);

createFailedTestCase(
"array with enum and undefined #3",
{
arrayStringAndEnumAndNoUndefined: ["foo", "bar", undefined],

Check warning on line 3033 in test/index.test.js

View workflow job for this annotation

GitHub Actions / Lint - ubuntu-latest - Node v16.x

Unexpected use of undefined
},
(msg) => expect(msg).toMatchSnapshot()
);
});

0 comments on commit 1a88581

Please sign in to comment.