jest-preset-angular icon indicating copy to clipboard operation
jest-preset-angular copied to clipboard

[Feature]: TextEncoder polyfill

Open DaSchTour opened this issue 2 years ago • 5 comments

🚀 Feature Proposal

Include some kind of polyfill/patch suggested in https://github.com/jsdom/jsdom/issues/2524

Motivation

With angular 15.1 a breaking change was introduced (https://github.com/angular/angular/issues/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

DaSchTour avatar Jan 16 '23 15:01 DaSchTour

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

Timebutt avatar Jan 17 '23 14:01 Timebutt

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.

alextrep96 avatar Jan 18 '23 21:01 alextrep96

@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 😅

DaSchTour avatar Jan 19 '23 13:01 DaSchTour

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

ahnpnl avatar Jan 27 '23 08:01 ahnpnl

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

SimenB avatar Jan 27 '23 09:01 SimenB