Semantic-UI-React无法启用调试

问题描述 投票:3回答:3

我正在使用semantic-ui-react,我正在尝试使用jest创建快照测试。但是,我一直收到这条消息。有人可以对此有所了解吗?我在nextjs中使用语义。

console.error node_modules/fbjs/lib/warning.js:36
      Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
    console.error node_modules/semantic-ui-react/dist/commonjs/lib/debug.js:30
      Semantic-UI-React could not enable debug.
    console.error node_modules/semantic-ui-react/dist/commonjs/lib/debug.js:31
      TypeError: Cannot read property 'debug' of undefined
reactjs jestjs semantic-ui-react next.js
3个回答
2
投票

当debug无法处理localStorage时会产生此警告,但不应调用它进行测试。确保ENV vars设置正确,你需要有NODE_ENV=test


2
投票

对于那些无法通过设置NODE_ENV=test来解决问题的人。另一个选项是使用或扩展一些测试设置脚本(即mocha -r setup.js):

// if you run Enzyme tests then you probably already have this import which creates global.window object
import 'jsdom-global/register'

global.window.localStorage = {};

对我来说两种选择都有效。我在Linux上运行我的测试。


0
投票

你在Windows上吗?如果是这样,你如何执行测试?我之前遇到了同样的问题,并且能够解决它。

我的package.json中有以下内容:

"run_test" : "set NODE_ENV=test && npm run test",
"test": "./node_modules/.bin/mocha --compilers js:babel-core/register --recursive",

然而,问题是windows会将你的NODE_ENV设置为“test”而不是“test”,注意尾随的空格。我的解决方案是通过删除空白来修复脚本编写:

"run_test" : "set NODE_ENV=test&&npm run test",
"test": "./node_modules/.bin/mocha --compilers js:babel-core/register --recursive",
© www.soinside.com 2019 - 2024. All rights reserved.