React + Jest + testing-library: "Please upgrade to at least react-dom@16.9.0 to remove this warning." ...但是 react-dom 已经是 16.9.0
React + Jest + testing-library: "Please upgrade to at least react-dom@16.9.0 to remove this warning." ...but react-dom is 16.9.0 already
我正在使用 Jest 和 testing-library/react
为我的 React 应用编写测试
我的测试通过了,但我无法摆脱这个错误:
It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.
我还看到此警告的多个实例:
Warning: An update to ConnectFunction inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
这是我的测试套件顶部的导入:
import React from "react";
import { BrowserRouter } from "react-router-dom";
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { createMemoryHistory } from 'history';
//testing-library/react
import { render, fireEvent, waitForElement, act } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import {
wait
} from '@testing-library/dom';
import MyComponent from '../MyComponent';
这是我的 package.json
"dependencies": {
"axios": "^0.18.1",
"react": "^16.11.0",
"react-dom": "^16.9.0",
"react-scripts": "2.1.5",
},
"devDependencies": {
"@testing-library/jest-dom": "^4.2.3",
"@testing-library/react": "^9.3.2",
}
react-dom
已经在 v16.9 上。我错过了什么?
令人沮丧的是,此错误似乎间歇性出现。当我尝试不同的东西时,它有时会在测试套件的几次运行中完全消失,然后 return.
经过几天与这个谜团的斗争,我终于重新启动了计算机,errors/warnings 消失了。我不明白为什么这很重要,因为我已经多次重新启动测试脚本,并且完全重新安装 node_modules
多次。我最好的猜测是它与从 react-test-renderer
模块到 testing-library
包装器的转换有关......但这纯粹是猜测。
- macOS v10.14.6
- 节点 v11.10.1
- npm v6.7.0
希望这能为其他人节省一些时间。
我正在使用 Jest 和 testing-library/react
为我的 React 应用编写测试我的测试通过了,但我无法摆脱这个错误:
It looks like you're using a version of react-dom that supports the "act" function, but not an awaitable version of "act" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.
我还看到此警告的多个实例:
Warning: An update to ConnectFunction inside a test was not wrapped in act(...).
When testing, code that causes React state updates should be wrapped into act(...):
act(() => {
/* fire events that update state */
});
/* assert on the output */
这是我的测试套件顶部的导入:
import React from "react";
import { BrowserRouter } from "react-router-dom";
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { createMemoryHistory } from 'history';
//testing-library/react
import { render, fireEvent, waitForElement, act } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
import {
wait
} from '@testing-library/dom';
import MyComponent from '../MyComponent';
这是我的 package.json
"dependencies": {
"axios": "^0.18.1",
"react": "^16.11.0",
"react-dom": "^16.9.0",
"react-scripts": "2.1.5",
},
"devDependencies": {
"@testing-library/jest-dom": "^4.2.3",
"@testing-library/react": "^9.3.2",
}
react-dom
已经在 v16.9 上。我错过了什么?
令人沮丧的是,此错误似乎间歇性出现。当我尝试不同的东西时,它有时会在测试套件的几次运行中完全消失,然后 return.
经过几天与这个谜团的斗争,我终于重新启动了计算机,errors/warnings 消失了。我不明白为什么这很重要,因为我已经多次重新启动测试脚本,并且完全重新安装 node_modules
多次。我最好的猜测是它与从 react-test-renderer
模块到 testing-library
包装器的转换有关......但这纯粹是猜测。
- macOS v10.14.6
- 节点 v11.10.1
- npm v6.7.0
希望这能为其他人节省一些时间。