TextEncoder issues on 26.0.1
See original GitHub issue🐛 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 a Uint8Array
it does indeed fail.
To Reproduce
This is a failing test -
it('encodes string as Uint8array', (): void => {
expect(
new TextEncoder().encode('Привет, мир!')
).toEqual(
new Uint8Array([208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130, 44, 32, 208, 188, 208, 184, 209, 128, 33])
);
});
The output does not match, rather it fails with -
expect(received).toEqual(expected) // deep equality
- Expected - 23
+ Received + 23
- Uint8Array [
- 208,
- 159,
- 209,
- 128,
- 208,
- 184,
- 208,
- 178,
- 208,
- 181,
- 209,
- 130,
- 44,
- 32,
- 208,
- 188,
- 208,
- 184,
- 209,
- 128,
- 33,
- ]
+ Uint8Array {
+ "0": 208,
+ "1": 159,
+ "10": 209,
+ "11": 130,
+ "12": 44,
+ "13": 32,
+ "14": 208,
+ "15": 188,
+ "16": 208,
+ "17": 184,
+ "18": 209,
+ "19": 128,
+ "2": 209,
+ "20": 33,
+ "3": 128,
+ "4": 208,
+ "5": 184,
+ "6": 208,
+ "7": 178,
+ "8": 208,
+ "9": 181,
+ }
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
System:
OS: macOS 10.15.2
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Binaries:
Node: 13.8.0 - /usr/local/bin/node
Yarn: 2.0.0-rc.30 - /usr/local/bin/yarn
npm: 6.13.7 - /usr/local/bin/npm
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:16 (3 by maintainers)
Top Results From Across the Web
ReferenceError: TextEncoder is not defined - Stack Overflow
This issue occurs in node 10 or lower version only. To resolve this issue upgrade node version to 12 or higher and then...
Read more >jest-environment-jsdom | Yarn - Package Manager
26.0.1. Fixes. [jest-circus] Backward compatibility for deprecated ... [jest-environment-node] Fix TextEncoder.encode not referencing same global Uint8Array ...
Read more >TextEncoder - Web APIs - MDN Web Docs
Chrome Edge
TextEncoder Full support. Chrome38. Toggle history Full support. Edge79. To...
TextEncoder() constructor Full support. Chrome38. Toggle history Full support. Edge79. To...
encode Full support....
Read more >ipfs-http-client/CHANGELOG.md - UNPKG
227, * dont include util.textencoder in the browser ... 1190, ## [26.0.1](https://github.com/ipfs/js-ipfs-http-client/compare/v26.0.0...v26.0.1) (2018-10-30).
Read more >matteoluigi's Content - Page 5 - Vectorworks Community Board
yeah, the only problems are when rendering the OpenGL viewports. Of course, my college mentioned, that he didn't have problems from the beginning......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there any progress on this issue?
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
Buffer
internally, so the test-case he has is the simplest and the actual underlying cause -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)