jest-preset-angular
jest-preset-angular copied to clipboard
[Feature]: TextEncoder polyfill
🚀 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
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
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 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 😅
@SimenB is this something Jest can take care of in jest-environment-jsdom
package?
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