You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(I used DeepL)
I was trying to write a test for a component that contains a Link and I got an act(...) error in the Router.
I would like to know your solution🙏
test("getLinkCompornents",async()=>{constprops={text: "go to hoge",linkTo: "/hogehoge"};constroutes=[{path: "/",element: <Top/>},{path: "hoge",element: <Hoge/>}];render(<Routerlocation={location}routes={routes}><LinkBox{...props}/></Router>);awaitscreen.findByText("go to hoge");});
console.error
Warning: An update to Router 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 */
This ensures that you're testing the behavior the user would see in the browser. Learn more at https://reactjs.org/link/wrap-tests-with-act
at Router (hogehoge/node_modules/@tanstack/react-location/src/index.tsx:492:3)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi,
use @tanstack/react-location: "3.7.4"
(I used DeepL)
I was trying to write a test for a component that contains a Link and I got an act(...) error in the Router.
I would like to know your solution🙏
https://codesandbox.io/s/goofy-glade-e3te67?file=/src/LinkBox.test.tsx
Beta Was this translation helpful? Give feedback.
All reactions