-
Notifications
You must be signed in to change notification settings - Fork 242
/
jest_after_env_setup.js
46 lines (36 loc) · 1.19 KB
/
jest_after_env_setup.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
40
41
42
43
44
45
46
/*
* Used for global imports before each test file is run (but after the Jest Environment is set up)
* https://jestjs.io/docs/configuration#setupfilesafterenv-array
*/
// React
import React from "react";
global.React = React;
// Jest dom (testing env)
import "@testing-library/jest-dom";
// Routes
window.Routes = global.Routes = require("./app/javascript/routes");
// Enzyme configuration
import {configure} from "enzyme";
import Adapter from "enzyme-adapter-react-16";
configure({adapter: new Adapter()});
// Jest fetch mock
require("jest-fetch-mock").enableMocks();
// Define HTMLElement.prototype.offsetParent
// Code from https://github.com/jsdom/jsdom/issues/1261#issuecomment-1765404346
Object.defineProperty(HTMLElement.prototype, "offsetParent", {
get() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
for (let element = this; element; element = element.parentNode) {
if (element.style?.display?.toLowerCase() === "none") {
return null;
}
}
if (this.stye?.position?.toLowerCase() === "fixed") {
return null;
}
if (this.tagName.toLowerCase() in ["html", "body"]) {
return null;
}
return this.parentNode;
},
});