forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpropEq.js
37 lines (30 loc) · 1.3 KB
/
propEq.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
30
31
32
33
34
35
36
37
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
var {Just} = require('./shared/Maybe.js');
describe('propEq', function() {
var obj1 = {name: 'Abby', age: 7, hair: 'blond'};
var obj2 = {name: 'Fred', age: 12, hair: 'brown'};
it('determines whether a particular property matches a given value for a specific object', function() {
eq(R.propEq('Abby', 'name', obj1), true);
eq(R.propEq('brown', 'hair', obj2), true);
eq(R.propEq('blond', 'hair', obj2), false);
});
it('handles number as property', function() {
var deities = ['Cthulhu', 'Dagon', 'Yog-Sothoth'];
eq(R.propEq('Cthulhu', 0, deities), true);
eq(R.propEq('Dagon', 1, deities), true);
eq(R.propEq('Yog-Sothoth', 2, deities), true);
eq(R.propEq('Yog-Sothoth', -1, deities), true);
eq(R.propEq(undefined, 3, deities), true);
});
it('has R.equals semantics', function() {
eq(R.propEq(0, 'value', {value: -0}), false);
eq(R.propEq(-0, 'value', {value: 0}), false);
eq(R.propEq(NaN, 'value', {value: NaN}), true);
eq(R.propEq(new Just([42]), 'value', {value: new Just([42])}), true);
});
it('returns false if called with a null or undefined object', function() {
eq(R.propEq('Abby', 'name', null), false);
eq(R.propEq('Abby', 'name', undefined), false);
});
});