Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

support: Avoid $(callback) to reduce zjquery complexity.

Anders Kaseorg5bdb734cdea5
diff --git a/web/src/support/support.ts b/web/src/support/support.ts
index a278ee534c8..b6ccf86c410 100644
--- a/web/src/support/support.ts
+++ b/web/src/support/support.ts
@@ -2,7 +2,7 @@ import ClipboardJS from "clipboard";
import $ from "jquery";
import assert from "minimalistic-assert";
-$(() => {
+function initialize(): void {
$("body").on("click", "button.scrub-realm-button", function (this: HTMLButtonElement, e) {
e.preventDefault();
const message =
@@ -100,4 +100,6 @@ $(() => {
}
},
);
-});
+}
+
+initialize();
diff --git a/web/tests/lib/index.cjs b/web/tests/lib/index.cjs
index 391d0307807..9477b076dc6 100644
--- a/web/tests/lib/index.cjs
+++ b/web/tests/lib/index.cjs
@@ -87,7 +87,6 @@ const noop = function () {};
require("../../src/templates.ts"); // register Zulip extensions
async function run_one_module(file) {
- zjquery.clear_initialize_function();
zjquery.clear_all_elements();
console.info("running test " + path.basename(file, ".test.cjs"));
test.set_current_file_name(file);
diff --git a/web/tests/lib/zjquery.cjs b/web/tests/lib/zjquery.cjs
index 3a2c7e2c479..852f2cf6521 100644
--- a/web/tests/lib/zjquery.cjs
+++ b/web/tests/lib/zjquery.cjs
@@ -82,24 +82,8 @@ function make_zjquery() {
return proxy;
}
- let initialize_function;
-
const zjquery = function (arg, arg2) {
- if (typeof arg === "function") {
- assert.ok(
- !initialize_function,
- `
- We are trying to avoid the $(...) mechanism
- for initializing modules in our codebase,
- and the code that you are compiling/running
- has tried to do this twice. Please either
- clean up the real code or reduce the scope
- of what you are testing in this test module.
- `,
- );
- initialize_function = arg;
- return undefined;
- }
+ assert.ok(typeof arg !== "function", "zjquery does not support $(callback)");
// If somebody is passing us an element, we return
// the element itself if it's been created with
@@ -141,14 +125,6 @@ function make_zjquery() {
return elems.get(selector);
};
- zjquery.get_initialize_function = function () {
- return initialize_function;
- };
-
- zjquery.clear_initialize_function = function () {
- initialize_function = undefined;
- };
-
zjquery.create = function (name, opts) {
assert.ok(!elems.has(name), "You already created an object with this name!!");
const $elem = new_elem(name, opts);
diff --git a/web/tests/support.test.cjs b/web/tests/support.test.cjs
index b73e7aaea69..bf6310091bd 100644
--- a/web/tests/support.test.cjs
+++ b/web/tests/support.test.cjs
@@ -21,10 +21,9 @@ mock_cjs("clipboard", class Clipboard {});
zrequire("../src/support/support");
-run_test("scrub_realm", () => {
- $.get_initialize_function()();
- const click_handler = $("body").get_on_handler("click", "button.scrub-realm-button");
+const click_handler = $("body").get_on_handler("click", "button.scrub-realm-button");
+run_test("scrub_realm", () => {
const $fake_this = $.create("fake-.scrub-realm-button");
$fake_this.attr = (name) => {
assert.equal(name, "data-string-id");