-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextEncoder issues on 26.0.1 #9983
Comments
@jacogr Does this happen only in JSDOM environment? If yes, can you try removing this line in your |
This example still fails. |
It does indeed fail like @TrySound suggested, even with the line commented. However, I can make both test cases pass by adding |
Also switch Jest testEnvironment to "node", due to this bug: jestjs/jest#9983
Hmm, seems like JSDOM doesn't support Is this
from https://github.com/jsdom/jsdom/blob/master/Changelog.md#1600? Seems to be in progress here: jsdom/whatwg-encoding#11 |
Node 11+ supports the TextEncoder global as part of their efforts to align further with browser environments |
Also TextEncoder is available in Node. |
What node supports and what jsdom supports is not the same thing. We usually point to jsdom for missing web APIs, this seems like the same thing? |
I dug, in the case of no TextEncoder it injects a polyfill in the project where this was uncovered, which is this -
So the issue is exactly the same as @TrySound reported - since doing the above will no doubt use
Sorry about the confusion, it has been literally 2 years since that polyfill was added. (Since it just worked in the meantime, totally lost track of it) |
We also polyfill this and have failing tests on JSDOM 16 with jest: // Polyfill for encoding which isn't present globally in jsdom
import { TextEncoder, TextDecoder } from 'util'
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder Since |
Just adding the fact that this bug also breaks |
Is there any progress on this issue? |
This reverts commit d7b4054.
This reverts commit d7b4054.
This reverts commit d7b4054.
This reverts commit d7b4054.
global.ArrayBuffer = ArrayBuffer;
global.Uint8Array = Uint8Array;
|
also if you won't patch packages, you could create your own custom environment extending JSDOMEnvironment, add this override after super() call in the env class constructor and use path to this file as your testEnvironment. Not that you couldn't use ES6 stuff in the env file, so use require('jest-environment-jsdom') and module.exports to export your env class |
The example in the OP fails in JSDOM env due to missing |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🐛 Bug Report
The
TextEncoder.encode
does not seem to yield a valid U8a, or rather, it cannot be compared. When the output from this is passed into a function expecting aUint8Array
it does indeed fail.To Reproduce
This is a failing test -
The output does not match, rather it fails with -
Expected behavior
It was still working on the 25.4.x version before I updated.
Link to repl or repo (highly encouraged)
Failing test included above.
envinfo
The text was updated successfully, but these errors were encountered: