When testing a function that uses either the TextEncoder or the TextDecoder I get:
ReferenceError: TextEncoder is not defined ReferenceError: TextDecoder is not defined
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:
import { TextEncoder, TextDecoder } from 'util' global.TextEncoder = TextEncoder global.TextDecoder = TextDecoder