Skip to content

Commit

Permalink
fix: create new ajv instance when additionalMetaSchemas prop is null,…
Browse files Browse the repository at this point in the history
… add tests
  • Loading branch information
epicfaace committed Feb 23, 2019
1 parent 05f6e7d commit d60e300
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default function validateFormData(
schema,
customValidate,
transformErrors,
additionalMetaSchemas
additionalMetaSchemas = []
) {
// add more schemas to validate against
if (
Expand Down
39 changes: 39 additions & 0 deletions test/Form_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createComponent,
createFormComponent,
createSandbox,
setProps,
} from "./test_utils";

describe("Form", () => {
Expand Down Expand Up @@ -1977,4 +1978,42 @@ describe("Form", () => {
expect(node.getAttribute("novalidate")).not.to.be.null;
});
});

describe("Meta schema updates", () => {
it("Should update allowed meta schemas when additionalMetaSchemas is changed", () => {
const formProps = {
liveValidate: true,
schema: {
$schema: "http://json-schema.org/draft-04/schema#",
type: "string",
minLength: 8,
pattern: "d+",
},
formData: "short",
additionalMetaSchemas: [],
};

const { comp } = createFormComponent(formProps);

expect(comp.state.errorSchema).eql({});

setProps(comp, {
...formProps,
additionalMetaSchemas: [
require("ajv/lib/refs/json-schema-draft-04.json"),
],
});

expect(comp.state.errorSchema).eql({
__errors: [
"should NOT be shorter than 8 characters",
'should match pattern "d+"',
],
});

setProps(comp, formProps);

expect(comp.state.errorSchema).eql({});
});
});
});

0 comments on commit d60e300

Please sign in to comment.