Files
zulip/frontend_tests/zjsunit/test.js
Steve Howell ac69450681 zjsunit: Clear $ elements in run_test.
We now call $.clear_all_elements at the top
of run_test.

We have to exempt two modules from the new regime:

    compose
    settings_user_groups

Also, if modules do set_global("$", ...) we don't
try to call the non-existent function.

It's possible we'll want to move to something like
this, but we might want to clean up the two
sloppy_$ modules first:

    // AVOID THIS:
    // const $ = require("zjquery")

    run_test("test widget", ({override, $}) => {
        override(foo, "bar", ...);
        $.create(...);
        // do stuff
    });
2021-02-23 07:55:43 -05:00

39 lines
821 B
JavaScript

"use strict";
const namespace = require("./namespace");
const $ = require("./zjquery");
let current_file_name;
let verbose = false;
exports.set_current_file_name = (value) => {
current_file_name = value;
};
exports.set_verbose = (value) => {
verbose = value;
};
exports.run_test = (label, f, opts) => {
const {sloppy_$} = opts || {};
if (verbose) {
console.info(" test: " + label);
}
if (!sloppy_$ && $.clear_all_elements) {
$.clear_all_elements();
}
try {
namespace.with_overrides(f);
} catch (error) {
console.info("-".repeat(50));
console.info(`test failed: ${current_file_name} > ${label}`);
console.info();
throw error;
}
// defensively reset blueslip after each test.
window.blueslip.reset();
};