Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

zjsunit: Restore missing fields correctly in with_field.

Anders Kaseorg3ccb4391d8f8
diff --git a/frontend_tests/zjsunit/namespace.js b/frontend_tests/zjsunit/namespace.js
index dc657fa8f52..965ad88d0f1 100644
--- a/frontend_tests/zjsunit/namespace.js
+++ b/frontend_tests/zjsunit/namespace.js
@@ -67,12 +67,17 @@ exports.restore = function () {
};
exports.with_field = function (obj, field, val, f) {
+ const had_val = Object.prototype.hasOwnProperty.call(obj, field);
const old_val = obj[field];
try {
obj[field] = val;
return f();
} finally {
- obj[field] = old_val;
+ if (had_val) {
+ obj[field] = old_val;
+ } else {
+ delete obj[field];
+ }
}
};