Chromium Code Reviews| Index: remoting/webapp/base/js/base_unittest.js |
| diff --git a/remoting/webapp/base/js/base_unittest.js b/remoting/webapp/base/js/base_unittest.js |
| index c2812ad8a3361e772856bbf383f2b05ec65f32a3..afa7c825ce8f55e3ada69eb52f2b6f1120b04e11 100644 |
| --- a/remoting/webapp/base/js/base_unittest.js |
| +++ b/remoting/webapp/base/js/base_unittest.js |
| @@ -54,6 +54,49 @@ QUnit.test('deepCopy(obj) should copy primitive types recursively', |
| assert.deepEqual(base.deepCopy([1, [2, [3]]]), [1, [2, [3]]]); |
| }); |
| +QUnit.test('copyWithoutNullFields returns a new object', |
| + function(assert) { |
| + var obj = { |
| + a: 'foo', |
| + b: 42 |
| + }; |
| + var copy = base.copyWithoutNullFields(obj); |
| + assert.notEqual(obj, copy); |
| + assert.deepEqual(obj, copy); |
| +}); |
| + |
| +QUnit.test('copyWithoutNullFields removes null and undefined fields', |
| + function(assert) { |
| + /** @const */ |
| + var obj = { |
| + a: 'foo', |
| + b: 42, |
| + nullField: null, |
| + undefinedField: undefined |
|
Jamie
2015/04/03 01:45:57
Add zero and '' fields to address my earlier comme
John Williams
2015/04/04 01:40:25
Done.
|
| + }; |
| + var copy = base.copyWithoutNullFields(obj); |
| + assert.equal(copy['a'], obj['a']); |
| + assert.equal(copy['b'], obj['b']); |
| + assert.ok(!('nullField' in copy)); |
| + assert.ok(!('undefinedField' in copy)); |
| +}); |
| + |
| +QUnit.test('copyWithoutNullFields(null) returns a new empty bject', |
| + function(assert) { |
| + assert.deepEqual( |
| + base.copyWithoutNullFields(null), |
| + {}); |
| + assert.notEqual( |
| + base.copyWithoutNullFields(null), |
| + base.copyWithoutNullFields(null)); |
| + assert.deepEqual( |
| + base.copyWithoutNullFields(undefined), |
| + {}); |
| + assert.notEqual( |
| + base.copyWithoutNullFields(undefined), |
| + base.copyWithoutNullFields(undefined)); |
| +}); |
| + |
| QUnit.test('modify the original after deepCopy(obj) should not affect the copy', |
| function(assert) { |
| var original = [1, 2, 3, 4]; |