【发布时间】:2021-09-28 18:04:03
【问题描述】:
在测试使用 TextEncoder 或 TextDecoder 的函数时,我得到:
ReferenceError: TextEncoder is not defined
ReferenceError: TextDecoder is not defined
我正在使用 jsdom,为什么这不起作用?
【问题讨论】:
标签: javascript jestjs jsdom
在测试使用 TextEncoder 或 TextDecoder 的函数时,我得到:
ReferenceError: TextEncoder is not defined
ReferenceError: TextDecoder is not defined
我正在使用 jsdom,为什么这不起作用?
【问题讨论】:
标签: javascript jestjs jsdom
虽然它应该与 jsdom 捆绑在一起,但它不与 jsdom 16 捆绑在一起。因此你可以像这样 polyfill:
import { TextEncoder, TextDecoder } from 'util'
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
【讨论】:
确保您的whatwg-url 软件包至少具有^10.0.0 版本
【讨论】: