小编bob*_*rks的帖子

测试 NextJS 和 Jest ReferenceError:TextEncoder 未定义

我在尝试学习如何测试 next.js 应用程序时收到此错误消息我尝试从配置顶部的 utils 导入文本编码器以及测试文件,但没有成功

  ReferenceError: TextEncoder is not defined



  at Object.<anonymous> (node_modules/whatwg-url/lib/encoding.js:2:21)
  at Object.<anonymous> (node_modules/whatwg-url/lib/url-state-machine.js:5:34)
  at Object.<anonymous> (node_modules/whatwg-url/lib/URL-impl.js:2:13)
  at Object.<anonymous> (node_modules/whatwg-url/lib/URL.js:442:14)
  at Object.<anonymous> (node_modules/whatwg-url/webidl2js-wrapper.js:3:13)
  at Object.<anonymous> (node_modules/whatwg-url/index.js:3:34)
  at Object.<anonymous> (node_modules/mongodb-connection-string-url/src/index.ts:1:1)
  at Object.<anonymous> (node_modules/mongodb/src/connection_string.ts:3:1)
  at Object.<anonymous> (node_modules/mongodb/src/mongo_client.ts:11:1)
  at Object.<anonymous> (node_modules/mongodb/src/change_stream.ts:17:1)
  at Object.<anonymous> (node_modules/mongodb/src/index.ts:3:1)
  at Object.<anonymous> (node_modules/mongoose/lib/drivers/node-mongodb-native/binary.js:8:16)
  at Object.<anonymous> (node_modules/mongoose/lib/drivers/node-mongodb-native/index.js:7:18)
  at Object.<anonymous> (node_modules/mongoose/lib/index.js:7:25)
  at Object.<anonymous> (node_modules/mongoose/index.js:8:18)
  at Object.<anonymous> (library/mongoDB.js:15:56)
  at Object.<anonymous> (library/players.js:15:18)
  at Object.<anonymous> (pages/index.js:18:18)
  at Object.<anonymous> (tests/index.test.js:6:53)
Run Code Online (Sandbox Code Playgroud)

玩笑配置文件

const nextJest = require('next/jest')
    const createJestConfig = nextJest({
  dir: './',
})
const …
Run Code Online (Sandbox Code Playgroud)

jestjs next.js react-testing-library

3
推荐指数
1
解决办法
3738
查看次数

标签 统计

jestjs ×1

next.js ×1

react-testing-library ×1