Skip to content

Commit

Permalink
Format tests (#1372)
Browse files Browse the repository at this point in the history
* test: fix typo

* test: reorg validate tests
  • Loading branch information
epicfaace authored and edi9999 committed Jul 30, 2019
1 parent 1d3e433 commit 45ec5f6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion test/SchemaField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ describe("SchemaField", () => {
}
}

it("should render it's own errors", () => {
it("should render its own errors", () => {
const { node } = createFormComponent({
schema,
uiSchema,
Expand Down
112 changes: 56 additions & 56 deletions test/validate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,62 +282,6 @@ describe("Validation", () => {
});
});

describe("toErrorList()", () => {
it("should convert an errorSchema into a flat list", () => {
expect(
toErrorList({
__errors: ["err1", "err2"],
a: {
b: {
__errors: ["err3", "err4"],
},
},
c: {
__errors: ["err5"],
},
})
).eql([
{ stack: "root: err1" },
{ stack: "root: err2" },
{ stack: "b: err3" },
{ stack: "b: err4" },
{ stack: "c: err5" },
]);
});
});

describe("transformErrors", () => {
const illFormedKey = "bar.'\"[]()=+*&^%$#@!";
const schema = {
type: "object",
properties: {
foo: { type: "string" },
[illFormedKey]: { type: "string" },
},
};
const newErrorMessage = "Better error message";
const transformErrors = errors => {
return [Object.assign({}, errors[0], { message: newErrorMessage })];
};

let errors;

beforeEach(() => {
const result = validateFormData(
{ foo: 42, [illFormedKey]: 41 },
schema,
undefined,
transformErrors
);
errors = result.errors;
});

it("should use transformErrors function", () => {
expect(errors).not.to.be.empty;
expect(errors[0].message).to.equal(newErrorMessage);
});
});

describe("Invalid schema", () => {
const schema = {
type: "object",
Expand Down Expand Up @@ -376,6 +320,62 @@ describe("Validation", () => {
});
});

describe("toErrorList()", () => {
it("should convert an errorSchema into a flat list", () => {
expect(
toErrorList({
__errors: ["err1", "err2"],
a: {
b: {
__errors: ["err3", "err4"],
},
},
c: {
__errors: ["err5"],
},
})
).eql([
{ stack: "root: err1" },
{ stack: "root: err2" },
{ stack: "b: err3" },
{ stack: "b: err4" },
{ stack: "c: err5" },
]);
});
});

describe("transformErrors", () => {
const illFormedKey = "bar.'\"[]()=+*&^%$#@!";
const schema = {
type: "object",
properties: {
foo: { type: "string" },
[illFormedKey]: { type: "string" },
},
};
const newErrorMessage = "Better error message";
const transformErrors = errors => {
return [Object.assign({}, errors[0], { message: newErrorMessage })];
};

let errors;

beforeEach(() => {
const result = validateFormData(
{ foo: 42, [illFormedKey]: 41 },
schema,
undefined,
transformErrors
);
errors = result.errors;
});

it("should use transformErrors function", () => {
expect(errors).not.to.be.empty;
expect(errors[0].message).to.equal(newErrorMessage);
});
});

describe("Form integration", () => {
let sandbox;

Expand Down

0 comments on commit 45ec5f6

Please sign in to comment.