我正在使用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发布于 2017-05-12 18:42:29
当debug不能处理localStorage时会产生这个警告,但是不应该在测试时调用它。确保ENV变量设置正确,您需要有NODE_ENV=test。
发布于 2017-12-31 10:08:36
对于那些不能解决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-06-07 17:35:32
您使用的是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”,而不是“测试”,注意尾随的空格。我的解决方案是通过删除空格来修复编写脚本:
"run_test" : "set NODE_ENV=test&&npm run test",
"test": "./node_modules/.bin/mocha --compilers js:babel-core/register --recursive",https://stackoverflow.com/questions/43916941
复制相似问题