-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
65 lines (51 loc) · 1.96 KB
/
test.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
let test = require('tape');
let Obj = require('./obj');
test('Obj.js', t => {
t.plan(4);
t.equal(typeof Obj, 'object');
t.test('#prop()', q => {
q.plan(1);
isFn(q, Obj.prop, '#prop');
});
t.test('#hasProp()', q => {
q.plan(6);
isFn(q, Obj.hasProp, '#hasProp');
var yep = Symbol('yep');
var nope = Symbol('nope');
var Parent = Object.create(Obj);
Parent.pProp = 1;
var Child = Object.create(Parent);
Child.cProp = 2;
Child[yep] = 'here i am!';
var Grandchild = Object.create(Child);
Grandchild.gcProp = 3;
q.ok(Grandchild.hasProp('pProp'), `has "pProp" (inherited from Parent)`);
q.ok(Grandchild.hasProp('cProp'), `has "cProp" (inherited from Child)`);
q.ok(Grandchild.hasProp(yep), `has "Symbol(yep)" (inherited from Child)`);
q.notOk(Grandchild.hasProp(nope), `doesn't have "Symbol(nope)" (not defined)`);
q.ok(Grandchild.hasProp('gcProp'), `has "gcProp" (set on self)`);
});
t.test('#chainHasProp()', q => {
q.plan(6);
isFn(q, Obj.chainHasProp, '#chainHasProp');
var yep = Symbol('yep');
var nope = Symbol('nope');
var Parent = Object.create(Obj);
Parent.pProp = 1;
var Child = Object.create(Parent);
Child.cProp = 2;
Child[yep] = 'test';
var Grandchild = Object.create(Child);
Grandchild.gcProp = 3;
q.ok(Grandchild.chainHasProp('pProp'), `chain has "pProp" (inherited from Parent)`);
q.ok(Grandchild.chainHasProp('cProp'), `chain has "cProp" (inherited from Child)`);
q.ok(Grandchild.chainHasProp(yep), `chain has "Symbol(yep)" (inherited from Child)`);
q.notOk(Grandchild.hasProp(nope), `doesn't have "Symbol(nope)" (not defined)`);
q.notOk(Grandchild.chainHasProp('gcProp'), `chain doesn't have "gcProp" (set on self)`);
});
});
//// HELPERS ///////////////////////////////////////////////////////////////////
function isFn(test, target, name) {
test.equal(typeof target, 'function', `${name} is a function`);
}