Skip to content

Commit 5f2b777

Browse files
committed
Fixes #18
conditionsMeet can handle testing values that are arrays of strings. However it still fails to test arrays of numbers.
1 parent c271482 commit 5f2b777

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/conditionsMeet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export default function conditionsMeet(condition, formData) {
3535
} else {
3636
let refVal = selectRef(ref, formData);
3737
if (Array.isArray(refVal)) {
38-
let condMeatOnce = refVal.some(val =>
39-
conditionsMeet(refCondition, val)
38+
let condMeatOnce = refVal.some(
39+
val => (isObject(val) ? conditionsMeet(refCondition, val) : false)
4040
);
4141
// It's either true for an element in an array or for the whole array
4242
return (

test/conditionsMeet.test.js

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ test("run predicate against array and elements", () => {
1414
expect(conditionsMeet(condition, [])).toBeTruthy();
1515
});
1616

17+
test("handles array of non-objects", () => {
18+
let condition = {
19+
options: {
20+
contains: "foo",
21+
},
22+
};
23+
expect(conditionsMeet(condition, { options: ["bar"] })).toBeFalsy();
24+
expect(conditionsMeet(condition, { options: [] })).toBeFalsy();
25+
expect(conditionsMeet(condition, { options: ["foo", "bar"] })).toBeTruthy();
26+
});
27+
1728
test("single line", () => {
1829
let condition = {
1930
firstName: "empty",

0 commit comments

Comments
 (0)