-
Notifications
You must be signed in to change notification settings - Fork 2
/
mocha.undernet.config.js
39 lines (33 loc) · 1.14 KB
/
mocha.undernet.config.js
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
import Undernet from "../js/src/index"
global.Undernet = Undernet
import { expect } from "chai"
global.expect = expect
const { JSDOM } = require("jsdom")
const dom = new JSDOM("<!doctype html><html><head></head><body></body></html>")
const { window } = dom
global.window = window
global.document = window.document
global.navigator = { userAgent: "node" }
/**
* Create and fire a keyboard event.
* @param {Number} which - The key code to simulate.
* @param {Boolean} shiftKey - Whether shift key should be used.
* @param {Element} node - The element to fire the event on.
*/
global.window.simulateKeyPress = (which, shiftKey = false, node = null) => {
const event = new KeyboardEvent("keydown", {
which,
shiftKey,
keyCode: which,
bubbles: true,
})
return node ? node.dispatchEvent(event) : document.dispatchEvent(event)
}
global.window.simulateMouseEvent = (name, node = null, bubbles = false, cancelable = false) => {
const event = new MouseEvent(name, {
bubbles: bubbles || true,
cancelable: cancelable || true,
relatedTarget: window
})
return node ? node.dispatchEvent(event) : document.dispatchEvent(event)
}