Skip to content

Commit

Permalink
Configure Jest to use mutationobserver-shim
Browse files Browse the repository at this point in the history
Stimulus relies on the MutationObserver browser API to work. Jest's
JSDOM doesn't implement this, so we need to shim it if we want to use
Jest to test our Stimulus controllers.
  • Loading branch information
tvararu committed Jul 13, 2023
1 parent b2ede13 commit 0441864
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "mutationobserver-shim";
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@
"jest": "^29.6.1",
"jest-environment-jsdom": "^29.6.1",
"jest-fetch-mock": "^3.0.3",
"mutationobserver-shim": "^0.3.7",
"prettier": "^3.0.0"
},
"packageManager": "[email protected]",
"jest": {
"collectCoverage": true,
"setupFilesAfterEnv": [
"<rootDir>/jest.setup.js"
],
"testPathIgnorePatterns": [
"app/assets/builds/",
"node_modules/",
"tests"
],
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4063,6 +4063,11 @@ [email protected]:
resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

mutationobserver-shim@^0.3.7:
version "0.3.7"
resolved "https://registry.yarnpkg.com/mutationobserver-shim/-/mutationobserver-shim-0.3.7.tgz#8bf633b0c0b0291a1107255ed32c13088a8c5bf3"
integrity sha512-oRIDTyZQU96nAiz2AQyngwx1e89iApl2hN5AOYwyxLUB47UYsU3Wv9lJWqH5y/QdiYkc5HQLi23ZNB3fELdHcQ==

nanomatch@^1.2.9:
version "1.2.13"
resolved "https://registry.yarnpkg.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
Expand Down

0 comments on commit 0441864

Please sign in to comment.