tests: Create empty jQuery objects with set_results.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2026-03-03 16:07:17 -08:00 committed by Tim Abbott
parent 87eafc74d2
commit 002e45df9a
6 changed files with 11 additions and 13 deletions

View File

@ -373,7 +373,7 @@ test_ui("validate_stream_message", ({override, mock_template}) => {
Array.from({length: 16}, (_, i) => i + 1),
);
let stream_wildcard_warning_rendered = false;
$("#compose_banner_area .wildcard_warning").length = 0;
$.set_results("#compose_banner_area .wildcard_warning", []);
mock_template("compose_banner/stream_wildcard_warning.hbs", false, (data) => {
stream_wildcard_warning_rendered = true;
assert.equal(data.subscriber_count, 16);

View File

@ -20,11 +20,10 @@ exports.mock_banners = () => {
$("#compose_banners .error").remove = noop;
$("#compose_banners .upload_banner").remove = noop;
const $stub = $.create("stub_to_remove");
const $stub = $.set_results("stub_to_remove", []);
const $cb = $("#compose_banners");
$stub.remove = noop;
$stub.length = 0;
$cb.closest = () => [];
$cb.set_find_results(".no_post_permissions", $stub);

View File

@ -300,7 +300,7 @@ run_test("initiate_search", ({override_rewire}) => {
override_rewire(search, "open_search_bar_and_close_narrow_description", () => {
search_bar_opened = true;
});
$(".navbar-search.expanded").length = 0;
$.set_results(".navbar-search.expanded", []);
$("#search_query").text("");
search.initiate_search();
assert.ok(typeahead_forced_open);

View File

@ -508,7 +508,7 @@ test("marked_subscribed (normal)", ({override, override_rewire}) => {
});
override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#channels_overlay_container .stream-row:not(.notdisplayed)").length = 0;
$.set_results("#channels_overlay_container .stream-row:not(.notdisplayed)", []);
override_rewire(stream_data, "set_max_channel_width_css_variable", noop);
stream_events.mark_subscribed(sub, [], "blue");
@ -547,7 +547,7 @@ test("marked_subscribed (color)", ({override, override_rewire}) => {
override(color_data, "pick_color", () => "green");
override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#channels_overlay_container .stream-row:not(.notdisplayed)").length = 0;
$.set_results("#channels_overlay_container .stream-row:not(.notdisplayed)", []);
// narrow state is undefined
{
@ -579,7 +579,7 @@ test("marked_subscribed (emails)", ({override, override_rewire}) => {
override(stream_settings_ui, "update_settings_for_subscribed", subs_stub.f);
override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#channels_overlay_container .stream-row:not(.notdisplayed)").length = 0;
$.set_results("#channels_overlay_container .stream-row:not(.notdisplayed)", []);
assert.ok(!stream_data.is_subscribed(sub.stream_id));
@ -610,7 +610,7 @@ test("mark_unsubscribed (update_settings_for_unsubscribed)", ({override, overrid
override(unread_ui, "update_unread_counts", noop);
override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#channels_overlay_container .stream-row:not(.notdisplayed)").length = 0;
$.set_results("#channels_overlay_container .stream-row:not(.notdisplayed)", []);
stream_events.mark_unsubscribed(sub);
const args = stub.get_args("sub");
@ -638,7 +638,7 @@ test("mark_unsubscribed (render_title_area)", ({override, override_rewire}) => {
override(unread_ui, "hide_unread_banner", noop);
override(user_profile, "update_user_profile_streams_list_for_users", noop);
$("#channels_overlay_container .stream-row:not(.notdisplayed)").length = 0;
$.set_results("#channels_overlay_container .stream-row:not(.notdisplayed)", []);
stream_events.mark_unsubscribed(sub);

View File

@ -91,8 +91,8 @@ function set_input_val(val) {
}
function stub_buddy_list_empty_list_message_lengths() {
$("#buddy-list-users-matching-view .empty-list-message").length = 0;
$("#buddy-list-other-users .empty-list-message").length = 0;
$.set_results("#buddy-list-users-matching-view .empty-list-message", []);
$.set_results("#buddy-list-other-users .empty-list-message", []);
}
test("clear_search with button", ({override}) => {

View File

@ -197,8 +197,7 @@ test("activate", ({override}) => {
// Test incoming widget events
const $empty_row = $.create("<empty row>");
$empty_row.length = 0;
const $empty_row = $.set_results("<empty row>", []);
let expected_message_id;