Skip to content

Commit

Permalink
fix #20
Browse files Browse the repository at this point in the history
  • Loading branch information
mavarazy committed Feb 16, 2018
1 parent c321295 commit babbd55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
6 changes: 0 additions & 6 deletions src/checkField.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,5 @@ const doCheckField = (fieldVal, rule) => {
};

export default function checkField(fieldVal, rule) {
if (Array.isArray(fieldVal)) {
let hasValidEntry = fieldVal.some(val => doCheckField(val, rule));
if (hasValidEntry) {
return true;
}
}
return doCheckField(fieldVal, rule);
}
10 changes: 0 additions & 10 deletions test/checkField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,3 @@ test("invalid rule", () => {
expect(checkField(60, { and: { less: 50, greater: 5 } })).toBeFalsy();
expect(checkField(60, { "&": { less: 50, greater: 5 } })).toBeFalsy();
});

test("check array", () => {
expect(checkField([], "empty")).toBeTruthy();
expect(checkField([""], "empty")).toBeTruthy();
expect(checkField([1, 2, 3, 4], { less: 50, greater: 5 })).toBeFalsy();
expect(checkField([1, 2, 3, 4, 5, 6], { less: 50, greater: 5 })).toBeTruthy();

expect(checkField(["B", "C", "D", "E"], { equal: "A" })).toBeFalsy();
expect(checkField(["A", "B", "C", "D", "E"], { equal: "A" })).toBeTruthy();
});
12 changes: 12 additions & 0 deletions test/conditionsMeet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ test("handles array of non-objects", () => {
expect(conditionsMeet(condition, { options: ["foo", "bar"] })).toBeTruthy();
});

// throws error
test("handles array of numbers", () => {
let condition = {
options: {
contains: 2,
},
};
expect(conditionsMeet(condition, { options: [1, 2] })).toBeTruthy();
expect(conditionsMeet(condition, { options: [1] })).toBeFalsy();
expect(conditionsMeet(condition, { options: [] })).toBeFalsy();
});

test("single line", () => {
let condition = {
firstName: "empty",
Expand Down

0 comments on commit babbd55

Please sign in to comment.