mirror of https://github.com/zulip/zulip.git
tests: Use setters instead of __Rewire__.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
52e59a9605
commit
8c60b66a95
|
@ -136,7 +136,7 @@ function stubbing(module, func_name_to_stub, test_function) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up defaults for most tests.
|
// Set up defaults for most tests.
|
||||||
hotkey.__Rewire__("processing_text", () => false);
|
hotkey.rewire_processing_text(() => false);
|
||||||
|
|
||||||
run_test("mappings", () => {
|
run_test("mappings", () => {
|
||||||
function map_press(which, shiftKey) {
|
function map_press(which, shiftKey) {
|
||||||
|
|
|
@ -346,11 +346,6 @@ exports.with_overrides = function (test_function) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const override_rewire = function (obj, prop, value, {unused = true} = {}) {
|
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(
|
assert.ok(
|
||||||
typeof obj === "object" || typeof obj === "function",
|
typeof obj === "object" || typeof obj === "function",
|
||||||
`We cannot override a function for ${typeof obj} objects`,
|
`We cannot override a function for ${typeof obj} objects`,
|
||||||
|
@ -377,19 +372,21 @@ exports.with_overrides = function (test_function) {
|
||||||
unused = false;
|
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(() => {
|
restore_callbacks.push(() => {
|
||||||
if (ok) {
|
if (ok) {
|
||||||
assert.ok(!unused, `${prop} never got invoked!`);
|
assert.ok(!unused, `${prop} never got invoked!`);
|
||||||
}
|
}
|
||||||
obj.__Rewire__(prop, old_value);
|
obj[rewire_prop](old_value);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const disallow_rewire = function (obj, prop) {
|
const disallow_rewire = function (obj, prop) {
|
||||||
// This is deprecated because it relies on the slow
|
|
||||||
// babel-plugin-rewire-ts plugin.
|
|
||||||
|
|
||||||
override_rewire(
|
override_rewire(
|
||||||
obj,
|
obj,
|
||||||
prop,
|
prop,
|
||||||
|
|
|
@ -22,7 +22,7 @@ message_lists.all_rendered_message_lists = () => [message_lists.current];
|
||||||
|
|
||||||
const people = zrequire("people");
|
const people = zrequire("people");
|
||||||
const message_events = zrequire("message_events");
|
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 message_helper = zrequire("message_helper");
|
||||||
const {set_realm} = zrequire("state_data");
|
const {set_realm} = zrequire("state_data");
|
||||||
const stream_data = zrequire("stream_data");
|
const stream_data = zrequire("stream_data");
|
||||||
|
|
|
@ -44,7 +44,7 @@ function test_with(fixture) {
|
||||||
final_select_id: undefined,
|
final_select_id: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
all_messages_data.__Rewire__("all_messages_data", {
|
all_messages_data.rewire_all_messages_data({
|
||||||
fetch_status: {
|
fetch_status: {
|
||||||
has_found_newest: () => fixture.has_found_newest,
|
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({
|
message_view.maybe_add_local_messages({
|
||||||
id_info,
|
id_info,
|
||||||
|
|
|
@ -252,7 +252,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
|
||||||
assert.equal(opts.updater(`channel:${verona_stream_id}`), "");
|
assert.equal(opts.updater(`channel:${verona_stream_id}`), "");
|
||||||
assert.ok(input_pill_displayed);
|
assert.ok(input_pill_displayed);
|
||||||
|
|
||||||
search.__Rewire__("is_using_input_method", true);
|
search.rewire_is_using_input_method(true);
|
||||||
_setup(terms);
|
_setup(terms);
|
||||||
input_pill_displayed = false;
|
input_pill_displayed = false;
|
||||||
mock_pill_removes(search.search_pill_widget);
|
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_query_box.text("test string");
|
||||||
|
|
||||||
search.__Rewire__("is_using_input_method", false);
|
search.rewire_is_using_input_method(false);
|
||||||
$searchbox_form.trigger("compositionend");
|
$searchbox_form.trigger("compositionend");
|
||||||
assert.ok(search.is_using_input_method);
|
assert.ok(search.is_using_input_method);
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ run_test("initialize", ({override, override_rewire, mock_template}) => {
|
||||||
expected_pill_display_value = "ver";
|
expected_pill_display_value = "ver";
|
||||||
_setup(terms);
|
_setup(terms);
|
||||||
ev.key = "Enter";
|
ev.key = "Enter";
|
||||||
search.__Rewire__("is_using_input_method", true);
|
search.rewire_is_using_input_method(true);
|
||||||
$searchbox_form.trigger(ev);
|
$searchbox_form.trigger(ev);
|
||||||
// No change on first Enter keyup event
|
// No change on first Enter keyup event
|
||||||
assert.ok(!is_blurred);
|
assert.ok(!is_blurred);
|
||||||
|
|
|
@ -29,7 +29,7 @@ function expand_sidebar() {
|
||||||
function make_cursor_helper() {
|
function make_cursor_helper() {
|
||||||
const events = [];
|
const events = [];
|
||||||
|
|
||||||
stream_list.__Rewire__("stream_cursor", {
|
stream_list.rewire_stream_cursor({
|
||||||
reset() {
|
reset() {
|
||||||
events.push("reset");
|
events.push("reset");
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue