mirror of
https://github.com/zulip/zulip.git
synced 2025-11-20 14:38:46 +00:00
zjsunit: Do not run $(...) automatically.
We have generally gone away from using $(...) initialization in modules that we test with zjsunit, but there are a few remaining special cases related to our billing and portico codebases.
This commit is contained in:
committed by
Steve Howell
parent
bc8647539c
commit
fbd3669461
@@ -70,6 +70,7 @@ function short_tb(tb) {
|
||||
}
|
||||
|
||||
function run_one_module(file) {
|
||||
zjquery.clear_initialize_function();
|
||||
zjquery.clear_all_elements();
|
||||
console.info("running test " + path.basename(file, ".js"));
|
||||
test.set_current_file_name(file);
|
||||
|
||||
@@ -486,13 +486,21 @@ function make_zjquery() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
let initialize_function;
|
||||
|
||||
const zjquery = function (arg, arg2) {
|
||||
if (typeof arg === "function") {
|
||||
// If somebody is passing us a function, we emulate
|
||||
// jQuery's behavior of running this function after
|
||||
// page load time. But there are no pages to load,
|
||||
// so we just call it right away.
|
||||
arg();
|
||||
if (initialize_function) {
|
||||
throw new Error(`
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -533,6 +541,14 @@ 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(!elems.has(name), "You already created an object with this name!!");
|
||||
const elem = new_elem(name, opts);
|
||||
|
||||
Reference in New Issue
Block a user