jest: ArrayBuffer regression in node env
🐛 Bug Report
https://github.com/facebook/jest/pull/7626 introduced regression
expect(new Uint8Array([]).buffer).toBeInstanceOf(ArrayBuffer);
fails with
Expected constructor: ArrayBuffer
Received constructor: ArrayBuffer
Received value: []
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 23
- Comments: 28 (5 by maintainers)
Commits related to this issue
- Implement the workaround from https://github.com/facebook/jest/issues/7780 — committed to dconeybe/FirebaseJsBug3096 by dconeybe 4 years ago
- Implement the workaround from https://github.com/facebook/jest/issues/7780 — committed to dconeybe/FirebaseJsBug3096 by dconeybe 4 years ago
- Update to create-react-app 4 - had to update eslint deps - ran into https://github.com/palantir/blueprint/issues/4112 - had to move beta.svg out of static/ - had to fix prettier formatting changes - ... — committed to pybricks/pybricks-code by dlech 4 years ago
- Update to create-react-app 4 - had to update eslint deps - ran into https://github.com/palantir/blueprint/issues/4112 - had to move beta.svg out of static/ - had to fix prettier formatting changes - ... — committed to pybricks/pybricks-code by dlech 4 years ago
- Update to create-react-app 4 - had to update eslint deps - ran into https://github.com/palantir/blueprint/issues/4112 - had to move beta.svg out of static/ - had to fix prettier formatting changes - ... — committed to pybricks/pybricks-code by dlech 4 years ago
- Update to create-react-app 4 - had to update eslint deps - ran into https://github.com/palantir/blueprint/issues/4112 - had to move beta.svg out of static/ - had to fix prettier formatting changes - ... — committed to pybricks/pybricks-code by dlech 4 years ago
- Revert "Bump react-scripts from 3.4.4 to 4.0.1" This reverts commit f825ea1199ee070097654e91c3d836c7d3d6f442. The upgrade to react-scripts includes an upgrade to jest-environment-jsdom which introdu... — committed to adrianclay/shopping-list by adrianclay 3 years ago
- important fix of nasty bug, see: https://github.com/facebook/jest/issues/7780\#issuecomment-705566017 — committed to radixdlt/radixdlt-javascript by Sajjon 3 years ago
- test: jest Uint8Array globals error https://github.com/facebook/jest/issues/7780 — committed to Conflux-Chain/helios by yqrashawn 3 years ago
- Fix compatability issue between firebase and jest See GitHub issue: https://github.com/facebook/jest/issues/7780 — committed to adrianclay/shopping-list by adrianclay 3 years ago
- Fix compatability issue between firebase and jest See GitHub issue: https://github.com/facebook/jest/issues/7780 — committed to adrianclay/shopping-list by adrianclay 3 years ago
- Update Jest to 27.0.0 Includes workaround for https://github.com/facebook/jest/issues/7780 — committed to wojtekmaj/react-pdf by wojtekmaj 3 years ago
- Tried upgrading to react-scripts v5 This doesn't work tho because Jest v27 seems to be required. The workarounds I see in https://github.com/facebook/jest/issues/7780 and https://github.com/firebase... — committed to beyondhb1079/s4us by josueetcom 2 years ago
I lied. I came back. Workaround:
Then in package.json:
@odbol You can also just add this
to the top of the file having this issue
i worked around this by adding
jest-environment-jsdom@25
as a dev dep per https://github.com/facebook/jest/issues/7780#issuecomment-669828353@odahcam @wi-ski
Thanks for sharing the workaround, but it seems to me that the solution is already out of date. I’ve just installed
jest-environment-node@^26.0.1
and injest.config.js
I set:That’s it. I didn’t need to extend the
NodeEnvironment
and overload the constructor. It just worked.Correct me if I’m wrong, but it seems that when
jest-environment-node
is installed then jest uses that module to configure the environment. So it looks like the bug is already fixed injest-environment-node
modlue.Am I right?
Setting
testEnvironment: 'node'
injest.config.js
works for me too without using the workaround. I do not need to installjest-environment-node
.true
in jest-environment-jsdom@25false
in jest-environment-jsdom@26This forced me to use mocha.
@SimenB
Execute the following code in each environment.(–env=node, --env=jsdom, and node).
In --env=node, results are not true.
It seems that
Uint8Array
also has the same issue asArrayBuffer
.So, create-react-app doesn’t allow you to override testEnvironment. Does anyone know a way to apply the workaround when using create-react-app?
I tried using jest { setupGlobals } but that wouldn’t let me modify the globals config.
I just had to put a
./
before thetestEnvironment
path:I am still experiencing this issue with jest-environment-jsdom@27. I tried the solution of adding a custom environment, but then the behavior of VSCode’s jest extension becomes all wonky. It can’t figure out the status of the tests. Ughh