Fix TextDecoder error in tests

This commit is contained in:
Franck Royer 2021-07-30 16:32:02 +10:00
parent 7d9f8c03c1
commit f0fe7dce02
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
3 changed files with 13 additions and 2 deletions

1
.gitignore vendored
View File

@ -2,7 +2,6 @@
.nyc_output .nyc_output
build build
node_modules node_modules
test
src/**.js src/**.js
coverage coverage
*.log *.log

View File

@ -16,7 +16,7 @@
"scripts": { "scripts": {
"start": "react-scripts start", "start": "react-scripts start",
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test --env=./test/custom-test-env.js",
"eject": "react-scripts eject" "eject": "react-scripts eject"
}, },
"eslintConfig": { "eslintConfig": {

View File

@ -0,0 +1,12 @@
const Environment = require('jest-environment-jsdom');
module.exports = class CustomTestEnvironment extends Environment {
async setup() {
await super.setup();
if (typeof this.global.TextEncoder === 'undefined') {
const { TextEncoder, TextDecoder } = require('util');
this.global.TextEncoder = TextEncoder;
this.global.TextDecoder = TextDecoder;
}
}
};