diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js index a77aa2a04a..ebcc2243f8 100644 --- a/frontend_tests/node_tests/activity.js +++ b/frontend_tests/node_tests/activity.js @@ -517,6 +517,11 @@ test_ui("insert_fred_then_alice_then_rename", (override) => { inserted_html = html; }; + let fred_removed; + fred_stub.remove = () => { + fred_removed = true; + }; + activity.redraw_user(alice.user_id); assert(inserted_html.indexOf('data-user-id="1"') > 0); assert(inserted_html.indexOf("user_circle_green") > 0); @@ -537,6 +542,7 @@ test_ui("insert_fred_then_alice_then_rename", (override) => { }; activity.redraw_user(fred_with_new_name.user_id); + assert(fred_removed); assert(appended_html.indexOf('data-user-id="2"') > 0); // restore old Fred data diff --git a/frontend_tests/node_tests/alert_words_ui.js b/frontend_tests/node_tests/alert_words_ui.js index 997db23ed1..4645195eab 100644 --- a/frontend_tests/node_tests/alert_words_ui.js +++ b/frontend_tests/node_tests/alert_words_ui.js @@ -26,6 +26,8 @@ run_test("render_alert_words_ui", () => { const alert_word_items = $.create("alert_word_items"); word_list.set_find_results(".alert-word-item", alert_word_items); + alert_word_items.remove = () => {}; + stub_templates((name, args) => { assert.equal(name, "settings/alert_word_settings_item"); return "stub-" + args.word; diff --git a/frontend_tests/node_tests/common.js b/frontend_tests/node_tests/common.js index 2fd17c1cfe..e5234e1033 100644 --- a/frontend_tests/node_tests/common.js +++ b/frontend_tests/node_tests/common.js @@ -32,6 +32,11 @@ run_test("copy_data_attribute_value", (override) => { const input = $.create("input"); + let removed; + input.remove = () => { + removed = true; + }; + override(document, "createElement", () => input); override(document, "execCommand", noop); @@ -60,6 +65,7 @@ run_test("copy_data_attribute_value", (override) => { faded_in = true; }; common.copy_data_attribute_value(elem, "admin-emails"); + assert(removed); assert(faded_in); assert(faded_out); }); diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.js index fff713868e..b0b0c56e93 100644 --- a/frontend_tests/node_tests/compose.js +++ b/frontend_tests/node_tests/compose.js @@ -314,7 +314,7 @@ test_ui("validate", () => { assert.equal($("#compose-error-msg").html(), i18n.t("Please specify a topic")); }); -test_ui("get_invalid_recipient_emails", () => { +test_ui("get_invalid_recipient_emails", (override) => { const welcome_bot = { email: "welcome-bot@example.com", user_id: 124, @@ -330,7 +330,7 @@ test_ui("get_invalid_recipient_emails", () => { people.initialize(page_params.user_id, params); - compose_state.private_message_recipient("welcome-bot@example.com"); + override(compose_state, "private_message_recipient", () => "welcome-bot@example.com"); assert.deepEqual(compose.get_invalid_recipient_emails(), []); }); diff --git a/frontend_tests/node_tests/input_pill.js b/frontend_tests/node_tests/input_pill.js index d253a126e0..cdecedfab2 100644 --- a/frontend_tests/node_tests/input_pill.js +++ b/frontend_tests/node_tests/input_pill.js @@ -403,6 +403,18 @@ run_test("insert_remove", () => { assert.equal(pill_input.text(), ""); assert.equal(widget.is_pending(), false); + let color_removed; + function set_colored_removed_func(color) { + return () => { + color_removed = color; + }; + } + + const pills = widget._get_pills_for_testing(); + for (const pill of pills) { + pill.$element.remove = set_colored_removed_func(pill.item.display_value); + } + const BACKSPACE = 8; let key_handler = container.get_on_handler("keydown", ".input"); @@ -415,6 +427,7 @@ run_test("insert_remove", () => { }); assert(removed); + assert.equal(color_removed, "YELLOW"); assert.deepEqual(widget.items(), [items.blue, items.red]); @@ -444,6 +457,7 @@ run_test("insert_remove", () => { preventDefault: noop, }); + assert.equal(color_removed, "BLUE"); assert(next_pill_focused); }); @@ -458,6 +472,11 @@ run_test("exit button on pill", () => { widget.appendValue("blue,red"); + const pills = widget._get_pills_for_testing(); + for (const pill of pills) { + pill.$element.remove = () => {}; + } + let next_pill_focused = false; const next_pill_stub = { diff --git a/frontend_tests/node_tests/settings_muting.js b/frontend_tests/node_tests/settings_muting.js index d6805c3a54..50dd447cec 100644 --- a/frontend_tests/node_tests/settings_muting.js +++ b/frontend_tests/node_tests/settings_muting.js @@ -56,6 +56,8 @@ run_test("settings", () => { return topic_tr_html; }; + topic_tr_html.remove = () => {}; + let topic_data_called = 0; topic_tr_html.attr = (opts) => { if (opts === "data-stream-id") { diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 8726b40239..f15b270453 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -99,7 +99,9 @@ run_test("unloaded", () => { }); function simulate_realm_domains_table() { - $("#realm_domains_table tbody").set_find_results("tr", $.create("realm-tr-stub")); + const tr_stub = $.create("realm-tr-stub"); + $("#realm_domains_table tbody").set_find_results("tr", tr_stub); + tr_stub.remove = () => {}; let appended; $("#realm_domains_table tbody").append = (html) => { diff --git a/frontend_tests/node_tests/settings_profile_fields.js b/frontend_tests/node_tests/settings_profile_fields.js index aebeb76760..fc6c7ff21d 100644 --- a/frontend_tests/node_tests/settings_profile_fields.js +++ b/frontend_tests/node_tests/settings_profile_fields.js @@ -54,6 +54,9 @@ function test_populate(opts) { table[0] = "stub"; + rows.remove = () => {}; + form.remove = () => {}; + let num_appends = 0; table.append = () => { num_appends += 1; diff --git a/frontend_tests/node_tests/spoilers.js b/frontend_tests/node_tests/spoilers.js index 0d7383b93f..ac940a6c84 100644 --- a/frontend_tests/node_tests/spoilers.js +++ b/frontend_tests/node_tests/spoilers.js @@ -22,6 +22,7 @@ const get_spoiler_elem = (title) => { const block = $.create(`block-${title}`); const header = $.create(`header-${title}`); const content = $.create(`content-${title}`); + content.remove = () => {}; header.text(title); block.set_find_results(".spoiler-header", header); block.set_find_results(".spoiler-content", content); diff --git a/frontend_tests/zjsunit/zjquery.js b/frontend_tests/zjsunit/zjquery.js index 635bb1825e..da346fd277 100644 --- a/frontend_tests/zjsunit/zjquery.js +++ b/frontend_tests/zjsunit/zjquery.js @@ -342,7 +342,14 @@ function make_new_elem(selector, opts) { return self; }, remove() { - return self; + throw new Error(` + We don't support remove in zjuery. + + You can do $(...).remove = ... if necessary. + + But you are probably writing too deep a test + for node testing. + `); }, removeData: noop, replaceWith() {