Skip to content

Commit babbd55

Browse files
committed
fix #20
1 parent c321295 commit babbd55

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

src/checkField.js

-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,5 @@ const doCheckField = (fieldVal, rule) => {
3131
};
3232

3333
export default function checkField(fieldVal, rule) {
34-
if (Array.isArray(fieldVal)) {
35-
let hasValidEntry = fieldVal.some(val => doCheckField(val, rule));
36-
if (hasValidEntry) {
37-
return true;
38-
}
39-
}
4034
return doCheckField(fieldVal, rule);
4135
}

test/checkField.test.js

-10
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,3 @@ test("invalid rule", () => {
7575
expect(checkField(60, { and: { less: 50, greater: 5 } })).toBeFalsy();
7676
expect(checkField(60, { "&": { less: 50, greater: 5 } })).toBeFalsy();
7777
});
78-
79-
test("check array", () => {
80-
expect(checkField([], "empty")).toBeTruthy();
81-
expect(checkField([""], "empty")).toBeTruthy();
82-
expect(checkField([1, 2, 3, 4], { less: 50, greater: 5 })).toBeFalsy();
83-
expect(checkField([1, 2, 3, 4, 5, 6], { less: 50, greater: 5 })).toBeTruthy();
84-
85-
expect(checkField(["B", "C", "D", "E"], { equal: "A" })).toBeFalsy();
86-
expect(checkField(["A", "B", "C", "D", "E"], { equal: "A" })).toBeTruthy();
87-
});

test/conditionsMeet.test.js

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ test("handles array of non-objects", () => {
2525
expect(conditionsMeet(condition, { options: ["foo", "bar"] })).toBeTruthy();
2626
});
2727

28+
// throws error
29+
test("handles array of numbers", () => {
30+
let condition = {
31+
options: {
32+
contains: 2,
33+
},
34+
};
35+
expect(conditionsMeet(condition, { options: [1, 2] })).toBeTruthy();
36+
expect(conditionsMeet(condition, { options: [1] })).toBeFalsy();
37+
expect(conditionsMeet(condition, { options: [] })).toBeFalsy();
38+
});
39+
2840
test("single line", () => {
2941
let condition = {
3042
firstName: "empty",

0 commit comments

Comments
 (0)