-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathseal.object.js
112 lines (93 loc) · 2.99 KB
/
seal.object.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* -----------------------------------------------------------------------------
* VITALS UNIT TESTS: vitals.seal.object
* -----------------------------------------------------------------------------
* @section strict
* @see [vitals.seal docs](https://github.com/imaginate/vitals/wiki/vitals.seal)
* @see [test api](https://github.com/imaginate/vitals/blob/master/test/setup/interface.js)
* @see [test helpers](https://github.com/imaginate/vitals/blob/master/test/setup/helpers.js)
*
* @author Adam Smith <adam@imaginate.life> (https://github.com/imaginate)
* @copyright 2017 Adam A Smith <adam@imaginate.life> (https://github.com/imaginate)
*
* Annotations:
* @see [JSDoc3](http://usejsdoc.org)
* @see [Closure Compiler JSDoc Syntax](https://developers.google.com/closure/compiler/docs/js-for-compiler)
*/
method('seal.object', 'seal.obj', function() {
should('shallowly seal the object', function() {
test(null, function() {
var obj = vitals.seal.obj(null);
assert( obj === null );
});
test({}, function() {
var obj = vitals.seal.obj({});
assert( is.sealed(obj) );
});
test('<function>', function() {
var func = function(){};
func = vitals.seal.obj(func);
assert( is.sealed(func) );
});
test({ a: {} }, function() {
var obj = vitals.seal.obj({ a: {} });
assert( is.sealed(obj) );
assert( !is.sealed(obj.a) );
});
test(null, false, function() {
var obj = vitals.seal.obj(null, false);
assert( obj === null );
});
test({}, false, function() {
var obj = vitals.seal.obj({}, false);
assert( is.sealed(obj) );
});
test('<function>', false, function() {
var func = function(){};
func = vitals.seal.obj(func, false);
assert( is.sealed(func) );
});
test({ a: {} }, false, function() {
var obj = vitals.seal.obj({ a: {} }, false);
assert( is.sealed(obj) );
assert( !is.sealed(obj.a) );
});
});
should('deeply seal the object', function() {
test(null, true, function() {
var obj = vitals.seal.obj(null, true);
assert( obj === null );
});
test({}, true, function() {
var obj = vitals.seal.obj({}, true);
assert( is.sealed(obj) );
});
test('<function>', true, function() {
var func = function(){};
func = vitals.seal.obj(func, true);
assert( is.sealed(func) );
});
test({ a: {} }, true, function() {
var obj = vitals.seal.obj({ a: {} }, true);
assert( is.sealed(obj) );
assert( is.sealed(obj.a) );
});
});
should('throw an error', function() {
test(function() {
assert.throws(function() {
vitals.seal.obj();
}, validTypeErr);
});
test('invalid', function() {
assert.throws(function() {
vitals.seal.obj('invalid');
}, validTypeErr);
});
test({}, 'invalid', function() {
assert.throws(function() {
vitals.seal.obj({}, 'invalid');
}, validTypeErr);
});
});
});