Skip to content

Commit c0daf9a

Browse files
committed
use jest-fixed-jsdom to fix global JS APIs
1 parent 54fbae9 commit c0daf9a

4 files changed

Lines changed: 16 additions & 11 deletions

File tree

eslint.config.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ const compat = new FlatCompat({
1717
allConfig: js.configs.all
1818
});
1919

20-
export default [...compat.extends(
20+
const base = compat.extends(
2121
"eslint:recommended",
2222
"plugin:@typescript-eslint/eslint-recommended",
2323
"plugin:@typescript-eslint/recommended",
24-
), {
24+
);
25+
26+
export default [...base, {
2527
plugins: {
2628
"@typescript-eslint": typescriptEslint,
2729
react,
@@ -31,6 +33,9 @@ export default [...compat.extends(
3133

3234
languageOptions: {
3335
parser: tsParser,
36+
globals: {
37+
window: "readonly",
38+
}
3439
},
3540

3641
rules: {
@@ -54,4 +59,4 @@ export default [...compat.extends(
5459

5560
"no-console": "error",
5661
},
57-
}];
62+
}];

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
"identity-obj-proxy": "^3.0.0",
154154
"jest": "^30.2.0",
155155
"jest-environment-jsdom": "^30.2.0",
156+
"jest-fixed-jsdom": "^0.0.11",
156157
"jest-pnp-resolver": "^1.2.3",
157158
"lint-staged": "^15.5.2",
158159
"node-sass-package-importer": "^5.3.3",
@@ -224,7 +225,7 @@
224225
"testMatch": [
225226
"<rootDir>/src/**/*(*.)@(spec|test).{js,jsx,ts,tsx}"
226227
],
227-
"testEnvironment": "jest-environment-jsdom",
228+
"testEnvironment": "jest-fixed-jsdom",
228229
"transform": {
229230
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest"
230231
},

src/test/setupTests.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import "regenerator-runtime/runtime";
2-
import { TextEncoder, TextDecoder } from "util";
32

4-
// Polyfill TextEncoder/TextDecoder for React 18
5-
global.TextEncoder = TextEncoder;
6-
global.TextDecoder = TextDecoder;
7-
8-
9-
if (window.document) {
3+
if (typeof window !== "undefined" && window.document) {
104
window.document.body.createTextRange = function () {
115
return {
126
setEnd: function () {},

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8195,6 +8195,11 @@ jest-environment-node@30.2.0:
81958195
jest-util "30.2.0"
81968196
jest-validate "30.2.0"
81978197

8198+
jest-fixed-jsdom@^0.0.11:
8199+
version "0.0.11"
8200+
resolved "https://registry.yarnpkg.com/jest-fixed-jsdom/-/jest-fixed-jsdom-0.0.11.tgz#67b5d5c4e9821bfb1e09a43139bfb0b9f4ec4f18"
8201+
integrity sha512-3UkjgM79APnmLVDnelrxdwz4oybD5qw6NLyayl7iCX8C8tJHeqjL9fmNrRlIrNiVJSXkF5t9ZPJ+xlM0kSwwYg==
8202+
81988203
jest-haste-map@30.2.0:
81998204
version "30.2.0"
82008205
resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-30.2.0.tgz#808e3889f288603ac70ff0ac047598345a66022e"

0 commit comments

Comments
 (0)