Skip to content

Commit b52218c

Browse files
author
Mateusz Puczynski
committed
add one proper test case
1 parent dc01736 commit b52218c

File tree

2 files changed

+28
-50
lines changed

2 files changed

+28
-50
lines changed

src/components/Form.js

+1
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,6 @@ if (process.env.NODE_ENV !== "production") {
300300
transformErrors: PropTypes.func,
301301
safeRenderCompletion: PropTypes.bool,
302302
formContext: PropTypes.object,
303+
metaSchema: PropTypes.object,
303304
};
304305
}

test/validate_test.js

+27-50
Original file line numberDiff line numberDiff line change
@@ -676,38 +676,12 @@ describe("Validation", () => {
676676
});
677677
});
678678
describe("Custom meta schema", () => {
679-
let sandboxErr;
680679
let onSubmit;
681680
let onError;
682-
let compWithMeta, nodeWithMeta, compWithoutMeta, nodeWithoutMeta;
683-
684-
beforeEach(() => {
685-
sandboxErr = sinon.sandbox.create();
686-
onSubmit = sandboxErr.spy();
687-
onError = sandboxErr.spy();
688-
const withMetaSchema = createFormComponent({
689-
schema,
690-
formData,
691-
metaSchema: require("ajv/lib/refs/json-schema-draft-04.json"),
692-
onSubmit,
693-
onError,
694-
});
695-
696-
compWithMeta = withMetaSchema.comp;
697-
nodeWithMeta = withMetaSchema.node;
698-
const withoutMetaSchema = createFormComponent({
699-
schema,
700-
formData,
701-
onSubmit,
702-
onError,
703-
});
704-
compWithoutMeta = withoutMetaSchema.comp;
705-
nodeWithoutMeta = withoutMetaSchema.node;
706-
});
707-
708-
afterEach(() => {
709-
sandboxErr.restore();
710-
});
681+
let comp, node;
682+
const formData = {
683+
datasetId: "no err",
684+
};
711685

712686
const schema = {
713687
$ref: "#/definitions/Dataset",
@@ -725,28 +699,31 @@ describe("Validation", () => {
725699
},
726700
},
727701
};
728-
const formData = {
729-
datasetId: "no err",
730-
};
731702

732-
it.only("asd", () => {
733-
Simulate.submit(nodeWithoutMeta);
734-
expect(
735-
nodeWithoutMeta.querySelectorAll(".errors li")
736-
).to.have.length.of(0);
737-
expect(compWithoutMeta.state.errors).to.have.lengthOf(0);
738-
});
739-
it.only("query select", () => {
740-
Simulate.submit(nodeWithMeta);
741-
expect(nodeWithMeta.querySelectorAll(".errors li")).to.have.length.of(
742-
1
743-
);
744-
expect(compWithMeta.state.errors[0].message).eql(
745-
`should match pattern "\\d+"`
746-
);
703+
beforeEach(() => {
704+
onSubmit = sandbox.spy();
705+
onError = sandbox.spy();
706+
const withMetaSchema = createFormComponent({
707+
schema,
708+
formData,
709+
liveValidate: true,
710+
metaSchema: require("ajv/lib/refs/json-schema-draft-04.json"),
711+
onSubmit,
712+
onError,
713+
});
714+
comp = withMetaSchema.comp;
715+
node = withMetaSchema.node;
747716
});
748-
it.only("dff", () => {
749-
// expect(compWithoutMeta.state.errors).to.have.length.of(0);
717+
718+
it("should be used to validate schema", () => {
719+
expect(node.querySelectorAll(".errors li")).to.have.length.of(1);
720+
expect(comp.state.errors).to.have.lengthOf(1);
721+
expect(comp.state.errors[0].message).eql(`should match pattern "\\d+"`);
722+
Simulate.change(node.querySelector("input"), {
723+
target: { value: "1234" },
724+
});
725+
expect(node.querySelectorAll(".errors li")).to.have.length.of(0);
726+
expect(comp.state.errors).to.have.lengthOf(0);
750727
});
751728
});
752729
});

0 commit comments

Comments
 (0)