Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
node tests: Avoid "orig_foo = bar" idiom.
Steve Howell64894fe8e4cd
diff --git a/frontend_tests/node_tests/drafts.js b/frontend_tests/node_tests/drafts.jsindex 2e0c67531ba..33a190548ef 100644--- a/frontend_tests/node_tests/drafts.js+++ b/frontend_tests/node_tests/drafts.js@@ -51,12 +51,10 @@ set_global("page_params", {});function stub_timestamp(timestamp, func) {- const original_func = Date.prototype.getTime;- Date.prototype.getTime = function () {+ function fake_time() {return timestamp;- };- func();- Date.prototype.getTime = original_func;+ }+ with_field(Date.prototype, "getTime", fake_time, func);}const legacy_draft = {diff --git a/frontend_tests/node_tests/pm_list.js b/frontend_tests/node_tests/pm_list.jsindex 79ce5d1cb30..deb24d57894 100644--- a/frontend_tests/node_tests/pm_list.js+++ b/frontend_tests/node_tests/pm_list.js@@ -223,10 +223,7 @@ run_test("is_all_privates", () => {});function with_fake_list(f) {- const orig = pm_list._build_private_messages_list;- pm_list._build_private_messages_list = () => "PM_LIST_CONTENTS";- f();- pm_list._build_private_messages_list = orig;+ with_field(pm_list, "_build_private_messages_list", () => "PM_LIST_CONTENTS", f);}run_test("expand", () => {@@ -261,15 +258,17 @@ run_test("update_private_messages", () => {find();};- const orig_is_all_privates = pm_list.is_all_privates;- pm_list.is_all_privates = () => true;-- pm_list.update_private_messages();+ with_field(+ pm_list,+ "is_all_privates",+ () => true,+ () => {+ pm_list.update_private_messages();+ },+ );assert(html_updated);assert($(".top_left_private_messages").hasClass("active-filter"));-- pm_list.is_all_privates = orig_is_all_privates;});});diff --git a/frontend_tests/node_tests/reactions.js b/frontend_tests/node_tests/reactions.jsindex b002ed17756..b501887bbbf 100644--- a/frontend_tests/node_tests/reactions.js+++ b/frontend_tests/node_tests/reactions.js@@ -177,14 +177,12 @@ run_test("basics", () => {assert.deepEqual(result, expected_result);});-run_test("sending", () => {+run_test("sending", (override) => {const message_id = 1001; // see above for setuplet emoji_name = "smile"; // should be a current reaction- const orig_remove_reaction = reactions.remove_reaction;- const orig_add_reaction = reactions.add_reaction;- reactions.remove_reaction = function () {};- reactions.add_reaction = function () {};+ override("reactions.add_reaction", () => {});+ override("reactions.remove_reaction", () => {});global.with_stub((stub) => {global.channel.del = stub.f;@@ -253,8 +251,6 @@ run_test("sending", () => {emoji_name = "unknown-emoji"; // Test sending an emoji unknown to frontend.blueslip.expect("warn", "Bad emoji name: " + emoji_name);reactions.toggle_emoji_reaction(message_id, emoji_name);- reactions.add_reaction = orig_add_reaction;- reactions.remove_reaction = orig_remove_reaction;});run_test("set_reaction_count", () => {@@ -617,15 +613,16 @@ run_test("error_handling", () => {user_id: 99,};- const original_func = reactions.current_user_has_reacted_to_emoji;- reactions.current_user_has_reacted_to_emoji = function () {- return true;- };- reactions.toggle_emoji_reaction(55, bogus_event.emoji_name);- reactions.current_user_has_reacted_to_emoji = original_func;+ with_field(+ reactions,+ "current_user_has_reacted_to_emoji",+ () => true,+ () => {+ reactions.toggle_emoji_reaction(55, bogus_event.emoji_name);+ },+ );reactions.add_reaction(bogus_event);-reactions.remove_reaction(bogus_event);});