diff --git a/web/tests/hotkey.test.js b/web/tests/hotkey.test.js index 7b3cee83ae..9339049cda 100644 --- a/web/tests/hotkey.test.js +++ b/web/tests/hotkey.test.js @@ -136,7 +136,7 @@ function stubbing(module, func_name_to_stub, test_function) { } // Set up defaults for most tests. -hotkey.__Rewire__("processing_text", () => false); +hotkey.rewire_processing_text(() => false); run_test("mappings", () => { function map_press(which, shiftKey) { diff --git a/web/tests/lib/namespace.js b/web/tests/lib/namespace.js index 0a81332c25..943aa6c579 100644 --- a/web/tests/lib/namespace.js +++ b/web/tests/lib/namespace.js @@ -346,11 +346,6 @@ exports.with_overrides = function (test_function) { }; const override_rewire = function (obj, prop, value, {unused = true} = {}) { - // This is deprecated because it relies on the slow - // babel-plugin-rewire-ts plugin. Consider alternatives such - // as exporting a helper function for tests from the module - // containing the function you need to mock. - assert.ok( typeof obj === "object" || typeof obj === "function", `We cannot override a function for ${typeof obj} objects`, @@ -377,19 +372,21 @@ exports.with_overrides = function (test_function) { unused = false; } - obj.__Rewire__(prop, new_value); + const rewire_prop = `rewire_${prop}`; + /* istanbul ignore if */ + if (!(rewire_prop in obj)) { + assert.fail(`You must define ${rewire_prop} to use override_rewire on ${prop}.`); + } + obj[rewire_prop](new_value); restore_callbacks.push(() => { if (ok) { assert.ok(!unused, `${prop} never got invoked!`); } - obj.__Rewire__(prop, old_value); + obj[rewire_prop](old_value); }); }; const disallow_rewire = function (obj, prop) { - // This is deprecated because it relies on the slow - // babel-plugin-rewire-ts plugin. - override_rewire( obj, prop, diff --git a/web/tests/message_events.test.js b/web/tests/message_events.test.js index b3f0c1cb54..fd6d080986 100644 --- a/web/tests/message_events.test.js +++ b/web/tests/message_events.test.js @@ -22,7 +22,7 @@ message_lists.all_rendered_message_lists = () => [message_lists.current]; const people = zrequire("people"); const message_events = zrequire("message_events"); -message_events.__Rewire__("update_views_filtered_on_message_property", () => {}); +message_events.rewire_update_views_filtered_on_message_property(() => {}); const message_helper = zrequire("message_helper"); const {set_realm} = zrequire("state_data"); const stream_data = zrequire("stream_data"); diff --git a/web/tests/narrow_local.test.js b/web/tests/narrow_local.test.js index b779c74115..688501902f 100644 --- a/web/tests/narrow_local.test.js +++ b/web/tests/narrow_local.test.js @@ -44,7 +44,7 @@ function test_with(fixture) { final_select_id: undefined, }; - all_messages_data.__Rewire__("all_messages_data", { + all_messages_data.rewire_all_messages_data({ fetch_status: { has_found_newest: () => fixture.has_found_newest, }, @@ -63,7 +63,7 @@ function test_with(fixture) { }, }); - narrow_state.__Rewire__("get_first_unread_info", () => fixture.unread_info); + narrow_state.rewire_get_first_unread_info(() => fixture.unread_info); message_view.maybe_add_local_messages({ id_info, diff --git a/web/tests/search.test.js b/web/tests/search.test.js index b5749b15c6..36252f146f 100644 --- a/web/tests/search.test.js +++ b/web/tests/search.test.js @@ -252,7 +252,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => { assert.equal(opts.updater(`channel:${verona_stream_id}`), ""); assert.ok(input_pill_displayed); - search.__Rewire__("is_using_input_method", true); + search.rewire_is_using_input_method(true); _setup(terms); input_pill_displayed = false; mock_pill_removes(search.search_pill_widget); @@ -272,7 +272,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => { $search_query_box.text("test string"); - search.__Rewire__("is_using_input_method", false); + search.rewire_is_using_input_method(false); $searchbox_form.trigger("compositionend"); assert.ok(search.is_using_input_method); @@ -357,7 +357,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => { expected_pill_display_value = "ver"; _setup(terms); ev.key = "Enter"; - search.__Rewire__("is_using_input_method", true); + search.rewire_is_using_input_method(true); $searchbox_form.trigger(ev); // No change on first Enter keyup event assert.ok(!is_blurred); diff --git a/web/tests/stream_search.test.js b/web/tests/stream_search.test.js index daf6d79ce5..950969d7f0 100644 --- a/web/tests/stream_search.test.js +++ b/web/tests/stream_search.test.js @@ -29,7 +29,7 @@ function expand_sidebar() { function make_cursor_helper() { const events = []; - stream_list.__Rewire__("stream_cursor", { + stream_list.rewire_stream_cursor({ reset() { events.push("reset"); },