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:
Steve Howell
2021-03-13 14:49:01 +00:00
committed by Steve Howell
parent bc8647539c
commit fbd3669461
8 changed files with 33 additions and 9 deletions

View File

@@ -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);

View 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);