Skip to content

Commit 94ef902

Browse files
author
intech
committed
fix tests
1 parent fe007b2 commit 94ef902

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/messages.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
arrayMax: "The '{field}' field must contain less than or equal to {expected} items.",
3232
arrayLength: "The '{field}' field must contain {expected} items.",
3333
arrayContains: "The '{field}' field must contain the '{expected}' item.",
34-
arrayUnique: "The '{field}' field value '{expected}' does not unique!",
34+
arrayUnique: "The '{actual}' value in '{field}' field does not unique the '{expected}' values.",
3535
arrayEnum: "The '{actual}' value in '{field}' field does not match any of the '{expected}' values.",
3636

3737
boolean: "The '{field}' field must be a boolean.",

lib/rules/array.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ module.exports = function({ schema, messages }, path, context) {
5757
if (schema.unique === true) {
5858
src.push(`
5959
if(len > Array.from(new Set(value)).length) {
60-
${this.makeError({ type: "arrayUnique", expected: "\"" + Array.from(new Set(value.filter((item, index) => value.indexOf(item) !== index))).join(", ") + "\"", actual: "value", messages })}
60+
${this.makeError({ type: "arrayUnique", expected: "Array.from(new Set(value.filter((item, index) => value.indexOf(item) !== index)))", actual: "value", messages })}
6161
}
6262
`);
6363
}
64-
64+
6565
if (schema.enum != null) {
6666
const enumStr = JSON.stringify(schema.enum);
6767
src.push(`

test/rules/array.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ describe("Test rule: array", () => {
7474
it("check unique", () => {
7575
const check = v.compile({ $$root: true, type: "array", unique: true });
7676

77-
expect(check(["bob","john","bob"])).toEqual({ type: "arrayUnique", expected: ["bob"] });
78-
expect(check(["bob","john","bob","bob","john"])).toEqual({ type: "arrayUnique", expected: ["bob","john"] });
79-
expect(check([1,2,1,false,true,false])).toEqual({ type: "arrayUnique", expected: [1,false] });
77+
expect(check(["bob","john","bob"])).toEqual([{ type: "arrayUnique", expected: ["bob"], actual: ["bob", "john", "bob"], message: "The 'bob,john,bob' value in '' field does not unique the 'bob' values." }]);
78+
expect(check(["bob","john","bob","bob","john"])).toEqual([{ type: "arrayUnique", expected: ["bob","john"], actual: ["bob","john","bob","bob","john"], message: "The 'bob,john,bob,bob,john' value in '' field does not unique the 'bob,john' values." }]);
79+
expect(check([1,2,1,false,true,false])).toEqual([{ type: "arrayUnique", expected: [1,false], actual: [1,2,1,false,true,false], message: "The '1,2,1,false,true,false' value in '' field does not unique the '1,false' values." }]);
8080
expect(check([{name:"bob"},{name:"john"},{name:"bob"}])).toEqual(true);
8181
expect(check(["john", "bob"])).toEqual(true);
8282
});

0 commit comments

Comments
 (0)