Skip to content

Commit

Permalink
Update pathSatisfies to handles empty path arguments (#2791)
Browse files Browse the repository at this point in the history
* Update `pathSatisfies` to handles empty `path` arguments

* Add negative test for `pathSatisfies` with empty `path`
  • Loading branch information
rjhilgefort authored and CrossEye committed Mar 1, 2019
1 parent b25ac73 commit ac58c96
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion source/pathSatisfies.js
Expand Up @@ -20,8 +20,9 @@ import path from './path';
* @example
*
* R.pathSatisfies(y => y > 0, ['x', 'y'], {x: {y: 2}}); //=> true
* R.pathSatisfies(R.is(Object), [], {x: {y: 2}}); //=> true
*/
var pathSatisfies = _curry3(function pathSatisfies(pred, propPath, obj) {
return propPath.length > 0 && pred(path(propPath, obj));
return pred(path(propPath, obj));
});
export default pathSatisfies;
8 changes: 6 additions & 2 deletions test/pathSatisfies.js
Expand Up @@ -14,8 +14,12 @@ describe('pathSatisfies', function() {
eq(R.pathSatisfies(isPositive, ['x', 'y'], {x: {z: 42}}), false);
});

it('returns false if the path is empty', function() {
eq(R.pathSatisfies(isPositive, [], {x: {z: 42}}), false);
it('handles empty paths by applying pred to data: positive', function() {
eq(R.pathSatisfies(R.is(Object), [], {x: {z: 42}}), true);
});

it('handles empty paths by applying pred to data: negative', function() {
eq(R.pathSatisfies(R.has('y'), [], {x: {z: 42}}), false);
});

it('returns false otherwise', function() {
Expand Down

0 comments on commit ac58c96

Please sign in to comment.