Delete ImmutableObject-test.js
Our syncing doesn't update these tests so just remove them.
Paul O’Shannessy committed
Jul 25, 2014 at 16:47 UTC
d526456951aabed2ab5af54e14e2a25478c70594
1 file changed
-302
src/vendor/immutable/__tests__/ImmutableObject-test.js
deleted
-302
@@ -1,302 +0,0 @@
1
-/**
2
- * Copyright 2013-2014 Facebook, Inc.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- *
16
- * @emails react-core
17
- */
18
-
19
-"use strict";
20
-
21
-var ImmutableObject;
22
-var Immutable;
23
-
24
-/**
25
- * To perform performance testing of using `ImmutableObject` vs. not using
26
- * `ImmutableObject`, such testing must be done with __DEV__ set to false.
27
- */
28
-describe('ImmutableObject', function() {
29
- var message;
30
- beforeEach(function() {
31
- ImmutableObject = require('ImmutableObject');
32
- Immutable = require('Immutable');
33
- });
34
-
35
- var testDev = function(message, testFunc) {
36
- it(message, function() {
37
- var old = window.__DEV__;
38
- window.__DEV__ = true;
39
- testFunc();
40
- window.__DEV__ = old;
41
- });
42
- };
43
-
44
- var testProd = function(message, testFunc) {
45
- it(message, function() {
46
- // Temporarily enter production mode
47
- var old = window.__DEV__;
48
- window.__DEV__ = false;
49
- testFunc();
50
- window.__DEV__ = old;
51
- });
52
- };
53
-
54
- var testDevAndProd = function(message, testFunc) {
55
- testDev(message + ':DEV', testFunc);
56
- testProd(message + ':PROD', testFunc);
57
- };
58
-
59
- /**
60
- * Deep clone a JSON-ifiable object. Jasmine doesn't support comparing frozen
61
- * objects, so we clone before asserting equality.
62
- */
63
- var deepClone = function(obj) {
64
- return JSON.parse(JSON.stringify(obj));
65
- };
66
-
67
- testDev('should be running in DEV', function() {
68
- expect(window.__DEV__).toBe(true);
69
- });
70
-
71
- testDev('should require initial map to be an object', function() {
72
- expect(function() {
73
- new ImmutableObject([1,2,3]);
74
- }).toThrow();
75
-
76
- expect(function() {
77
- new ImmutableObject('asdf');
78
- }).toThrow();
79
-
80
- expect(function() {
81
- new ImmutableObject({oldField: 'asdf', fieldTwo: null});
82
- }).not.toThrow();
83
- });
84
-
85
- testDevAndProd('should extend Immutable', function() {
86
- var object = new ImmutableObject({foo: 'bar'});
87
- expect (object instanceof Immutable).toBe(true);
88
- expect (object instanceof ImmutableObject).toBe(true);
89
- });
90
-
91
- testDev('should not exceed maximum call stack size with nodes', function() {
92
- var node = document.createElement('div');
93
- var object = new ImmutableObject({node: node});
94
- expect(object.node).toBe(node);
95
- });
96
-
97
- testDevAndProd('should not throw when not mutating directly', function() {
98
- var io = new ImmutableObject({oldField: 'asdf'});
99
- expect(function() {
100
- ImmutableObject.set(io, {newField: null}); // not a mutation!
101
- }).not.toThrow();
102
- });
103
-
104
- testDev('should prevent shallow field addition when strict', function() {
105
- if (window.callPhantom) return;
106
- expect(function() {
107
- var io = new ImmutableObject({oldField: 'asdf'});
108
- io.newField = 'this will not work';
109
- }).toThrow();
110
- });
111
-
112
- testDev('should prevent shallow field mutation when strict', function() {
113
- if (window.callPhantom) return;
114
- expect(function() {
115
- var io = new ImmutableObject({oldField: 'asdf'});
116
- io.oldField = 'this will not work!';
117
- }).toThrow();
118
- });
119
-
120
- testDev('should prevent deep field addition when strict', function() {
121
- if (window.callPhantom) return;
122
- expect(function() {
123
- var io =
124
- new ImmutableObject({shallowField: {deepField: {oldField: null}}});
125
- io.shallowField.deepField.oldField = 'this will not work!';
126
- }).toThrow();
127
- });
128
-
129
- testDev('should prevent deep field mutation when strict', function() {
130
- if (window.callPhantom) return;
131
- expect(function() {
132
- var io =
133
- new ImmutableObject({shallowField: {deepField: {oldField: null}}});
134
- io.shallowField.deepField.newField = 'this will not work!';
135
- }).toThrow();
136
- });
137
-
138
- testDevAndProd(
139
- 'should create object with same structure when set with {}',
140
- function() {
141
- var beforeIO =
142
- new ImmutableObject({shallowField: {deepField: {oldField: null}}});
143
- var afterIO = ImmutableObject.set(beforeIO, {});
144
- expect(afterIO).toEqual(beforeIO);
145
- expect(afterIO).not.toBe(beforeIO);
146
- }
147
- );
148
-
149
- testDevAndProd(
150
- 'should create distinct object with shallow field insertion',
151
- function() {
152
- if (window.callPhantom) return;
153
- var beforeStructure = {
154
- oldShallowField: {
155
- deepField: {
156
- oldField: null
157
- }
158
- }
159
- };
160
-
161
- var delta = {
162
- newShallowField: 'newShallowFieldHere'
163
- };
164
-
165
- var expectedAfterStructure = {
166
- oldShallowField: {
167
- deepField: {
168
- oldField: null
169
- }
170
- },
171
- newShallowField: 'newShallowFieldHere'
172
- };
173
-
174
- var beforeIO = new ImmutableObject(beforeStructure);
175
- var afterIO = ImmutableObject.set(beforeIO, delta);
176
- expect(deepClone(afterIO)).toEqual(expectedAfterStructure);
177
- expect(afterIO).not.toBe(beforeIO);
178
- }
179
- );
180
-
181
- testDevAndProd(
182
- 'should create distinct object with shallow field mutation',
183
- function() {
184
- if (window.callPhantom) return;
185
- var beforeStructure = {
186
- oldShallowField: {
187
- deepField: {
188
- oldField: null
189
- }
190
- }
191
- };
192
-
193
- var delta = {
194
- oldShallowField: 'this will clobber the old field'
195
- };
196
-
197
- var expectedAfterStructure = {
198
- oldShallowField: 'this will clobber the old field'
199
- };
200
-
201
- var beforeIO = new ImmutableObject(beforeStructure);
202
- var afterIO = ImmutableObject.set(beforeIO, delta);
203
- expect(deepClone(afterIO)).toEqual(expectedAfterStructure);
204
- expect(afterIO).not.toBe(beforeIO);
205
- }
206
- );
207
-
208
- message = 'should create distinct object with deep field insertion';
209
- testDevAndProd(message, function() {
210
- if (window.callPhantom) return;
211
- var beforeStructure = {
212
- oldShallowField: {
213
- deepField: {
214
- oldField: null
215
- }
216
- }
217
- };
218
-
219
- var delta = {
220
- oldShallowField: {newDeepField: 'hello'}
221
- };
222
-
223
- // ImmutableObject does not yet support deep merging with
224
- // ImmutableObject.set().
225
- var expectedAfterStructure = {
226
- oldShallowField: {newDeepField: 'hello'}
227
- };
228
-
229
- var beforeIO = new ImmutableObject(beforeStructure);
230
- var afterIO = ImmutableObject.set(beforeIO, delta);
231
- expect(deepClone(afterIO)).toEqual(expectedAfterStructure);
232
- expect(afterIO).not.toBe(beforeIO);
233
- });
234
-
235
- message =
236
- 'should tolerate arrays at deeper levels and prevent mutation on them';
237
- testDev(message, function() {
238
- if (window.callPhantom) {
239
- // PhantomJS has a bug with Object.freeze and Arrays.
240
- // https://github.com/ariya/phantomjs/issues/10817
241
- return;
242
- }
243
- var beforeStructure = {
244
- shallowField: [1,'second field',3]
245
- };
246
- var io = new ImmutableObject(beforeStructure);
247
- expect(function() {
248
- io.newField = 'nope!';
249
- }).toThrow();
250
- expect(function() {
251
- io.shallowField[0] = 'nope!';
252
- }).toThrow();
253
- expect(io.shallowField[1]).toEqual('second field');
254
- });
255
-
256
- message = 'should provide a setProperty interface as sugar for set()';
257
- testDevAndProd(message, function() {
258
- if (window.callPhantom) return;
259
- var beforeIO = new ImmutableObject({initialField: null});
260
- var afterIO =
261
- ImmutableObject.setProperty(beforeIO, 'anotherField', 'anotherValue');
262
- expect(deepClone(afterIO)).toEqual({
263
- initialField: null,
264
- anotherField: 'anotherValue'
265
- });
266
- expect(afterIO).not.toBe(beforeIO);
267
- });
268
-
269
- message = 'should recursively create distinct objects when deep copying';
270
- testDevAndProd(message, function() {
271
- if (window.callPhantom) return;
272
- var beforeIO = new ImmutableObject({
273
- a: {b: 'b', c: {}, d: 'd', e: new ImmutableObject({f: 'f'}) }
274
- });
275
- var afterIO = ImmutableObject.setDeep(beforeIO, {
276
- a: {b: {}, c: 'C', e: {f: 'F', g: 'G'}, h: 'H'}
277
- });
278
- expect(deepClone(afterIO)).toEqual({
279
- a: {b: {}, c: 'C', d: 'd', e: {f: 'F', g: 'G'}, h: 'H'}
280
- });
281
- expect(afterIO).not.toBe(beforeIO);
282
- expect(afterIO.a).not.toBe(beforeIO.a);
283
- expect(afterIO.a.e).not.toBe(beforeIO.a.e);
284
- });
285
-
286
- testDevAndProd('should deep copy member immutability', function() {
287
- if (window.callPhantom) return;
288
- var beforeIO = new ImmutableObject({
289
- a: {b: new ImmutableObject({c: 'c'}), e: {f: 'f'}}
290
- });
291
- var afterIO = ImmutableObject.setDeep(beforeIO, {
292
- a: {b: {d: 'D'}, e: new ImmutableObject({g: 'G'})}
293
- });
294
- expect(deepClone(afterIO)).toEqual({
295
- a: {b: {c: 'c', d: 'D'}, e: {f: 'f', g: 'G'}}
296
- });
297
- expect(afterIO instanceof Immutable).toBe(true);
298
- expect(afterIO.a.b instanceof Immutable).toBe(true);
299
- expect(afterIO.a.e instanceof Immutable).toBe(true);
300
- });
301
-});
302
-