Skip to content

Commit 60d16be

Browse files
committed
Merge pull request facebook#1330 from spicyj/clone-imm
Clone objects in immutable tests.
2 parents 42e20a1 + 99e943d commit 60d16be

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/vendor/immutable/__tests__/ImmutableObject-test.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ describe('ImmutableObject', function() {
5656
testProd(message + ':PROD', testFunc);
5757
};
5858

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+
5967
testDev('should be running in DEV', function() {
6068
expect(window.__DEV__).toBe(true);
6169
});
@@ -165,7 +173,7 @@ describe('ImmutableObject', function() {
165173

166174
var beforeIO = new ImmutableObject(beforeStructure);
167175
var afterIO = ImmutableObject.set(beforeIO, delta);
168-
expect(afterIO).toEqual(expectedAfterStructure);
176+
expect(deepClone(afterIO)).toEqual(expectedAfterStructure);
169177
expect(afterIO).not.toBe(beforeIO);
170178
}
171179
);
@@ -192,7 +200,7 @@ describe('ImmutableObject', function() {
192200

193201
var beforeIO = new ImmutableObject(beforeStructure);
194202
var afterIO = ImmutableObject.set(beforeIO, delta);
195-
expect(afterIO).toEqual(expectedAfterStructure);
203+
expect(deepClone(afterIO)).toEqual(expectedAfterStructure);
196204
expect(afterIO).not.toBe(beforeIO);
197205
}
198206
);
@@ -220,7 +228,7 @@ describe('ImmutableObject', function() {
220228

221229
var beforeIO = new ImmutableObject(beforeStructure);
222230
var afterIO = ImmutableObject.set(beforeIO, delta);
223-
expect(afterIO).toEqual(expectedAfterStructure);
231+
expect(deepClone(afterIO)).toEqual(expectedAfterStructure);
224232
expect(afterIO).not.toBe(beforeIO);
225233
});
226234

@@ -251,7 +259,7 @@ describe('ImmutableObject', function() {
251259
var beforeIO = new ImmutableObject({initialField: null});
252260
var afterIO =
253261
ImmutableObject.setProperty(beforeIO, 'anotherField', 'anotherValue');
254-
expect(afterIO).toEqual({
262+
expect(deepClone(afterIO)).toEqual({
255263
initialField: null,
256264
anotherField: 'anotherValue'
257265
});
@@ -267,7 +275,7 @@ describe('ImmutableObject', function() {
267275
var afterIO = ImmutableObject.setDeep(beforeIO, {
268276
a: {b: {}, c: 'C', e: {f: 'F', g: 'G'}, h: 'H'}
269277
});
270-
expect(afterIO).toEqual({
278+
expect(deepClone(afterIO)).toEqual({
271279
a: {b: {}, c: 'C', d: 'd', e: {f: 'F', g: 'G'}, h: 'H'}
272280
});
273281
expect(afterIO).not.toBe(beforeIO);
@@ -283,7 +291,7 @@ describe('ImmutableObject', function() {
283291
var afterIO = ImmutableObject.setDeep(beforeIO, {
284292
a: {b: {d: 'D'}, e: new ImmutableObject({g: 'G'})}
285293
});
286-
expect(afterIO).toEqual({
294+
expect(deepClone(afterIO)).toEqual({
287295
a: {b: {c: 'c', d: 'D'}, e: {f: 'f', g: 'G'}}
288296
});
289297
expect(afterIO instanceof Immutable).toBe(true);

0 commit comments

Comments
 (0)