-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathauto-events-cmdclick.test.js
More file actions
45 lines (42 loc) · 1.46 KB
/
auto-events-cmdclick.test.js
File metadata and controls
45 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const { expect } = require("chai");
const { JSDOM } = require("jsdom");
const { readFileSync } = require("fs");
const vm = require("vm");
describe("auto-events cmd-click", function () {
it("allows meta click without preventing default", function () {
const html =
'<!doctype html><html><body><a id="doc" href="https://docs.example.com/">Doc</a></body></html>';
const dom = new JSDOM(html, {
url: "https://simpleanalytics.com/",
runScripts: "outside-only",
pretendToBeVisual: true,
});
const context = dom.getInternalVMContext();
vm.runInContext(
"window.sa_event = function(){}; window.sa_event_loaded = true;",
context
);
const script = readFileSync("dist/latest/auto-events.js", "utf8");
vm.runInContext(script, context);
const link = dom.window.document.getElementById("doc");
const normalEvent = new dom.window.MouseEvent("click", {
bubbles: true,
cancelable: true,
});
const metaEvent = new dom.window.MouseEvent("click", {
bubbles: true,
cancelable: true,
metaKey: true,
});
const normalReturn = dom.window.saAutomatedLink(
link,
"outbound",
normalEvent
);
const metaReturn = dom.window.saAutomatedLink(link, "outbound", metaEvent);
expect(normalEvent.defaultPrevented).to.equal(true);
expect(metaEvent.defaultPrevented).to.equal(false);
expect(normalReturn).to.equal(false);
expect(metaReturn).to.equal(true);
});
});