Skip to content
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

[Feature]: TextEncoder polyfill #1914

Closed
DaSchTour opened this issue Jan 16, 2023 · 5 comments · Fixed by #2535
Closed

[Feature]: TextEncoder polyfill #1914

DaSchTour opened this issue Jan 16, 2023 · 5 comments · Fixed by #2535

Comments

@DaSchTour
Copy link

🚀 Feature Proposal

Include some kind of polyfill/patch suggested in jsdom/jsdom#2524

Motivation

With angular 15.1 a breaking change was introduced (angular/angular#48748) so that TextEncoder is now needed. This breaks tests in an jest + jsdom env.

While jsdom does not support TextEncoder angular test with jest will fail.

Example

No response

@Timebutt
Copy link

For reference, the workaround to polyfill TextEncoder in a jsdom environment is adding this to your setupJest.ts file (or whatever you use to set up global mocks):

import { TextEncoder, TextDecoder } from 'util'
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder

@alextrep96
Copy link

Also having this issue with Angular 15.1. We are using an Nx monorepo and multiple libraries just started failing because of this issue. The workaround from @Timebutt works, but it requires us to patch all our currently failing libs and future libs until this is made compatible.

We already have import 'jest-preset-angular/setup-jest'; in all our test-setup.ts files. It would make a lot of sense for it to fix the compatibility issue.

@DaSchTour
Copy link
Author

@alextrep96 I have the same setup and it's really frustrating issue. I thought I was the only one having the problem. Somehow relieving to not be the only one with the issue 😅

@ahnpnl ahnpnl added the 🚀 Feature Request new suggested feature label Jan 20, 2023
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jan 27, 2023

@SimenB is this something Jest can take care of in jest-environment-jsdom package?

@SimenB
Copy link

SimenB commented Jan 27, 2023

No, we're waiting for upstream support. We've had lots of issues with added polyfills before, so I don't wanna add any more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants