Skip to content

Commit

Permalink
polyfil for TextDecoder in jsdom as according to jsdom/jsdom#2524
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdean-digicatapult committed Jan 11, 2024
1 parent 410dcec commit 5e9376c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions jest-setup.ts
@@ -0,0 +1,12 @@
import * as util from 'util'

// ref: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
// ref: https://github.com/jsdom/jsdom/issues/2524
Object.defineProperty(window, 'TextEncoder', {
writable: true,
value: util.TextEncoder
})
Object.defineProperty(window, 'TextDecoder', {
writable: true,
value: util.TextDecoder
})
4 changes: 4 additions & 0 deletions jest.config.json
Expand Up @@ -20,6 +20,10 @@
"testPathIgnorePatterns": [
"<rootDir>/lib/"
],
"setupFiles": [
"dotenv/config",
"./jest-setup.ts"
],
"testEnvironment": "jsdom",
"moduleNameMapper": {
"^(\\.{1,2}/.*\\.util)\\.js$": "$1.mock",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -21,11 +21,11 @@
"clean": "rm -rf ./lib",
"build": "npm run clean && tsc",
"build:watch": "npm run clean && tsc --watch",
"coverage": "jest --coverage --setupFiles dotenv/config",
"coverage": "jest --coverage",
"depcheck": "depcheck",
"lint": "eslint .",
"storybook": "storybook dev -p 9000",
"test": "jest --setupFiles dotenv/config"
"test": "jest"
},
"peerDependencies": {
"react": "^18.2.0"
Expand Down

0 comments on commit 5e9376c

Please sign in to comment.