-
Notifications
You must be signed in to change notification settings - Fork 46.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: False-positive Warning: An update to Link inside a test was not wrapped in act(...)
after upgrading React to 17.0.1?
#20568
Comments
Thanks for the report.
It's not clear from the code you posted that the code isn't doing any state updates. Could you reduce this as much as possible so that we end up with a single test and every bit of component code visible in the repro? Otherwise it'll be very hard to identify how that false positive was produced. |
Could you clarify what's a Every single test throw this warning, so any of them will be a good place to experiment. I can make a repro with the smallest possible code for easier understanding too, I'll do that now. |
I've updated the description and added a proper reproduction branch/PR on my own repository. |
@Vadorequest were you able to solve this? I'm facing this issue right now and my poor console buffer is not happy about it.
"dependencies": {
"@material-ui/core": "^4.11.4",
"@material-ui/lab": "^4.0.0-alpha.58",
"@types/jsdom": "^16.2.12",
"jsdom": "^16.6.0",
"mysql": "^2.18.1",
"next": "^11.0.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"reflect-metadata": "^0.1.13",
"swr": "^0.5.6",
"typeorm": "^0.2.34"
},
"devDependencies": {
"@babel/core": "^7.14.6",
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-proposal-decorators": "^7.14.5",
"@testing-library/react": "^11.2.7",
"@types/chai": "^4.2.18",
"@types/jest": "^26.0.23",
"@types/mocha": "^8.2.2",
"@types/node": "^15.12.2",
"@types/react": "17.0.11",
"@typescript-eslint/eslint-plugin": "^4.26.1",
"@typescript-eslint/parser": "^4.26.1",
"babel-plugin-transform-typescript-metadata": "^0.3.2",
"chai": "^4.3.4",
"eslint": "^7.28.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.24.0",
"jest": "^27.0.4",
"mocha": "^9.0.0",
"node-mocks-http": "^1.10.1",
"prettier": "^2.3.1",
"sqlite3": "^5.0.2",
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.3.2"
} |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
I have the same issue in a login form with react testing library, the test pass perfectly but I still getting this error, I will try with await act(async () => {
fireEvent.input(username, {
target: {
value: 'asdasd1',
},
})
}) fireEvent.input(username, {
target: {
value: 'asdasd1',
},
}) I need at least can hide this error |
The update is caused by The fix is to unmount the component once your test is finished if you don't care about the state of the component when next considers it visible. In summary:
|
The problem was solved for me but I don't know how |
React version: 17.0.1
React-test-renderer: 17.0.1
Steps To Reproduce
yarn test
Link to code example:
PR: UnlyEd/next-right-now#248
Reproducing:
git clone https://github.com/UnlyEd/next-right-now.git next-right-now
cd next-right-now && git checkout react-link-jest-act-repro
cp .env.local.example .env.local
- Uses the default ENV variables when running locallyyarn
yarn test
(then type "a" to run them all)The current behavior
Using the following code, all tests pass locally (but fail on Vercel) (and were passing prior upgrading react packages), but I get tons of warning no, such as
Warning: An update to Link inside a test was not wrapped in act(...).
and those warnings are new, and I couldn't get rid of them:I18nLink.test.tsx
:I18nLink
component:The expected behavior
The current code shouldn't yield any warning. It's mistakenly reporting warnings thinking the tests update the react state, but we don't. We simply render a React component, without interacting with it, therefore the react state shouldn't change. I believe this is a false-positive warning.
The text was updated successfully, but these errors were encountered: