3

我正在使用语义-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
4

3 回答 3

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 上运行我的测试。

于 2017-12-31T02:08:36.370 回答
2

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

于 2017-05-12T10:42:29.183 回答
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",
于 2017-06-07T09:35:31.903 回答