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
build
node_modules
test
src/**.js
coverage
*.log

View File

@ -16,7 +16,7 @@
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"test": "react-scripts test --env=./test/custom-test-env.js",
"eject": "react-scripts eject"
},
"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;
}
}
};