reactjs - 错误: It looks like you called `mount()` without a global document being loaded

标签 reactjs enzyme

我正在尝试安装一个组件以使用 enzyme 进行测试,并收到此错误。

最佳答案

npm install --save-dev --save-exact jsdom jsdom-global

然后:

import 'jsdom-global/register'; //at the top of file, even before importing React

更多信息here .

替代方案:如果您使用带有 enzyme 的笑话-

package.json 中,将 jest 的测试环境指定为 jsdom,如下所示:

"jest": {
  "testEnvironment": "jsdom"
}

我遇到了同样的问题,它对我来说效果很好。

关于reactjs - 错误: It looks like you called `mount()` without a global document being loaded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37104033/

相关文章:

javascript - 您可以/如何将构造函数添加到对象中?

javascript - 用 Jest 检查传递的函数作为 prop

javascript - 组件正在将电子邮件类型的受控输入更改为不受控

mysql - 如何在react js中从mysql中的表中呈现正确的日期

reactjs - Quill 工具栏未呈现(显示图标路径而不是呈现)

javascript - 类型错误 : Cannot read property 'prepareStyles' of undefined

javascript - 如何在 React 测试用例中使用 document.getElementById() (JEST+ ENZYME)

testing - API 请求在 Travis-CI 上失败

javascript - 开 Jest : Add component children elements to snapshot

reactjs - 如何正确初始化 React 中的函数?