Skip to content

Commit

Permalink
Merge pull request #19 from mrclay/18_array_of_string
Browse files Browse the repository at this point in the history
Fixes #18
  • Loading branch information
mavarazy authored Feb 16, 2018
2 parents c271482 + 5f2b777 commit c321295
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/conditionsMeet.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export default function conditionsMeet(condition, formData) {
} else {
let refVal = selectRef(ref, formData);
if (Array.isArray(refVal)) {
let condMeatOnce = refVal.some(val =>
conditionsMeet(refCondition, val)
let condMeatOnce = refVal.some(
val => (isObject(val) ? conditionsMeet(refCondition, val) : false)
);
// It's either true for an element in an array or for the whole array
return (
Expand Down
11 changes: 11 additions & 0 deletions test/conditionsMeet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ test("run predicate against array and elements", () => {
expect(conditionsMeet(condition, [])).toBeTruthy();
});

test("handles array of non-objects", () => {
let condition = {
options: {
contains: "foo",
},
};
expect(conditionsMeet(condition, { options: ["bar"] })).toBeFalsy();
expect(conditionsMeet(condition, { options: [] })).toBeFalsy();
expect(conditionsMeet(condition, { options: ["foo", "bar"] })).toBeTruthy();
});

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

0 comments on commit c321295

Please sign in to comment.