/
freeze.js
112 lines (93 loc) · 2.95 KB
/
freeze.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.freeze
* -----------------------------------------------------------------------------
* @section strict
* @see [vitals.freeze docs](https://github.com/imaginate/vitals/wiki/vitals.freeze)
* @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('freeze', function() {
should('shallowly freeze the object', function() {
test(null, function() {
var obj = vitals.freeze(null);
assert( obj === null );
});
test({}, function() {
var obj = vitals.freeze({});
assert( is.frozen(obj) );
});
test('<function>', function() {
var func = function(){};
func = vitals.freeze(func);
assert( is.frozen(func) );
});
test({ a: {} }, function() {
var obj = vitals.freeze({ a: {} });
assert( is.frozen(obj) );
assert( !is.frozen(obj.a) );
});
test(null, false, function() {
var obj = vitals.freeze(null, false);
assert( obj === null );
});
test({}, false, function() {
var obj = vitals.freeze({}, false);
assert( is.frozen(obj) );
});
test('<function>', false, function() {
var func = function(){};
func = vitals.freeze(func, false);
assert( is.frozen(func) );
});
test({ a: {} }, false, function() {
var obj = vitals.freeze({ a: {} }, false);
assert( is.frozen(obj) );
assert( !is.frozen(obj.a) );
});
});
should('deeply freeze the object', function() {
test(null, true, function() {
var obj = vitals.freeze(null, true);
assert( obj === null );
});
test({}, true, function() {
var obj = vitals.freeze({}, true);
assert( is.frozen(obj) );
});
test('<function>', true, function() {
var func = function(){};
func = vitals.freeze(func, true);
assert( is.frozen(func) );
});
test({ a: {} }, true, function() {
var obj = vitals.freeze({ a: {} }, true);
assert( is.frozen(obj) );
assert( is.frozen(obj.a) );
});
});
should('throw an error', function() {
test(function() {
assert.throws(function() {
vitals.freeze();
}, validTypeErr);
});
test('invalid', function() {
assert.throws(function() {
vitals.freeze('invalid');
}, validTypeErr);
});
test({}, 'invalid', function() {
assert.throws(function() {
vitals.freeze({}, 'invalid');
}, validTypeErr);
});
});
});