Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1996)

Unified Diff: remoting/webapp/base/js/base_unittest.js

Issue 1055313002: Added mock_xhr module w/ unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: for re-review Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..34d00d7161ca0a4d9d97eb884dfc74fd2ff8f807 100644
--- a/remoting/webapp/base/js/base_unittest.js
+++ b/remoting/webapp/base/js/base_unittest.js
@@ -54,6 +54,53 @@ 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,
+ zero: 0,
+ emptyString: '',
+ nullField: null,
+ undefinedField: undefined
+ };
+ var copy = base.copyWithoutNullFields(obj);
+ assert.equal(copy['a'], obj['a']);
+ assert.equal(copy['b'], obj['b']);
+ assert.equal(copy['zero'], 0);
+ assert.equal(copy['emptyString'], '');
+ 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];

Powered by Google App Engine
This is Rietveld 408576698