-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
94 lines (78 loc) · 3.03 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
'use strict';
require('mocha');
var assert = require('assert');
var isDescriptor = require('./');
var noop = function() {};
describe('isDescriptor', function() {
describe('value type', function() {
it('should be false when not an object:', function() {
assert(!isDescriptor('a'));
assert(!isDescriptor(null));
assert(!isDescriptor([]));
});
});
describe('check for descriptor', function() {
it('should return true if the property exists', function() {
var obj = {};
obj.foo = null;
Object.defineProperty(obj, 'bar', {
value: 'xyz'
});
Object.defineProperty(obj, 'baz', {
get: function() {
return 'aaa';
}
});
assert(isDescriptor(obj, 'foo'));
assert(isDescriptor(obj, 'bar'));
assert(isDescriptor(obj, 'baz'));
});
});
describe('data descriptor:', function() {
it('should be false when the object has invalid properties:', function() {
assert(!isDescriptor({value: 'foo', get: noop}));
assert(!isDescriptor({get: noop, value: noop}));
});
it('should not be false when the object has unrecognize properties:', function() {
assert(isDescriptor({value: 'foo', bar: 'baz'}));
assert(isDescriptor({value: 'foo', bar: 'baz'}));
});
it('should be true when the object has valid properties:', function() {
assert(isDescriptor({value: 'foo'}));
assert(isDescriptor({value: noop}));
});
it('should be false when a value is not the correct type:', function() {
assert(!isDescriptor({value: 'foo', enumerable: 'foo'}));
assert(!isDescriptor({value: 'foo', configurable: 'foo'}));
assert(!isDescriptor({value: 'foo', writable: 'foo'}));
});
});
describe('accessor descriptor:', function() {
it('should be false when the object has invalid properties:', function() {
assert(!isDescriptor({get: noop, writable: true}));
assert(!isDescriptor({get: noop, value: true}));
});
it('should not be false when the object has unrecognize properties:', function() {
assert(isDescriptor({get: noop, set: noop, bar: 'baz'}));
});
it('should be false when an accessor is not a function:', function() {
assert(!isDescriptor({get: noop, set: 'baz'}));
assert(!isDescriptor({get: 'foo', set: noop}));
assert(!isDescriptor({get: 'foo', bar: 'baz'}));
assert(!isDescriptor({get: 'foo', set: 'baz'}));
});
it('should be false when "get" is not a function', function() {
assert(!isDescriptor({set: noop}));
assert(!isDescriptor({get: 'foo'}));
});
it('should be true when the object has valid properties:', function() {
assert(isDescriptor({get: noop, set: noop}));
assert(isDescriptor({get: noop}));
});
it('should be false when a value is not the correct type:', function() {
assert(!isDescriptor({get: noop, set: noop, enumerable: 'foo'}));
assert(!isDescriptor({set: noop, configurable: 'foo'}));
assert(!isDescriptor({get: noop, configurable: 'foo'}));
});
});
});