Skip to content

Commit

Permalink
Fix ReferenceError: TextEncoder is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
akunzai committed Nov 9, 2023
1 parent 5b2feab commit 6e9daeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 2 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ module.exports = {
"!src/environment/*.ts",
"!src/mocks/*.js",
],
testEnvironment: "./jest.environment.js",
testEnvironmentOptions: {
customExportConditions: [''],
},
globals: {
Request,
Response,
TextEncoder,
TextDecoder
},
}
};
11 changes: 11 additions & 0 deletions jest.environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Environment from "jest-environment-jsdom";

export default class CustomTestEnvironment extends Environment {
async setup() {
await super.setup();
this.global.TextEncoder = TextEncoder;
this.global.TextDecoder = TextDecoder;
this.global.Response = Response;
this.global.Request = Request;
}
};

0 comments on commit 6e9daeb

Please sign in to comment.