Files
zulip/frontend_tests/node_tests/keydown_util.js
Anders Kaseorg 89aa3155a9 node_tests: Don’t read from most deprecated global variables.
We still need to write to these globals with set_global because the
code being tested reads from them, but the tests themselves should
never need to read from them.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-10 07:40:22 -08:00

46 lines
916 B
JavaScript

"use strict";
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const {make_zjquery} = require("../zjsunit/zjquery");
set_global("$", make_zjquery());
const keydown_util = zrequire("keydown_util");
run_test("test_early_returns", () => {
const stub = $.create("stub");
const opts = {
elem: stub,
handlers: {
left_arrow: () => {
throw new Error("do not dispatch this with alt key");
},
},
};
keydown_util.handle(opts);
const e1 = {
type: "keydown",
which: 17, // not in keys
};
stub.trigger(e1);
const e2 = {
type: "keydown",
which: 13, // no handler
};
stub.trigger(e2);
const e3 = {
type: "keydown",
which: 37,
altKey: true, // let browser handle
};
stub.trigger(e3);
});