forked from ramda/ramda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeys.js
38 lines (31 loc) · 1 KB
/
keys.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
38
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('keys', function() {
var obj = {a: 100, b: [1, 2, 3], c: {x: 200, y: 300}, d: 'D', e: null, f: undefined};
function C() { this.a = 100; this.b = 200; }
C.prototype.x = function() { return 'x'; };
C.prototype.y = 'y';
var cobj = new C();
it("returns an array of the given object's own keys", function() {
eq(R.keys(obj).sort(), ['a', 'b', 'c', 'd', 'e', 'f']);
});
it('works with hasOwnProperty override', function() {
eq(R.keys({
hasOwnProperty: false
}), ['hasOwnProperty']);
});
it('works for primitives', function() {
eq(R.keys(null), []);
eq(R.keys(undefined), []);
eq(R.keys(55), []);
eq(R.keys('foo'), []);
eq(R.keys(true), []);
eq(R.keys(false), []);
eq(R.keys(NaN), []);
eq(R.keys(Infinity), []);
eq(R.keys([]), []);
});
it("does not include the given object's prototype properties", function() {
eq(R.keys(cobj).sort(), ['a', 'b']);
});
});