Skip to content
Advertisement

Why am I getting “TextEncoder is not defined” in Jest?

When testing a function that uses either the TextEncoder or the TextDecoder I get:

JavaScript

I am using jsdom, so why is this not working?

Advertisement

Answer

While it should be bundled with jsdom, it isn’t with jsdom 16. Therefore you can polyfill like so:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement