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