forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpathSatisfies.js
29 lines (20 loc) · 915 Bytes
/
pathSatisfies.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('pathSatisfies', function() {
var isPositive = function(n) { return n > 0; };
it('returns true if the specified object path satisfies the given predicate', function() {
eq(R.pathSatisfies(isPositive, ['x', 1, 'y'], {x: [{y: -1}, {y: 1}]}), true);
});
it('returns false if the specified path does not exist', function() {
eq(R.pathSatisfies(isPositive, ['x', 'y'], {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() {
eq(R.pathSatisfies(isPositive, ['x', 'y'], {x: {y: 0}}), false);
});
});