testing-library

How to solve the “update was not wrapped in act()” warning in testing-library-react?

筅森魡賤 提交于 2020-06-16 04:47:32
问题 I'm working with a simple component that does a side effect. My test passes, but I'm getting the warning Warning: An update to Hello inside a test was not wrapped in act(...). . I'm also don't know if waitForElement is the best way to write this test. My component export default function Hello() { const [posts, setPosts] = useState([]); useEffect(() => { const fetchData = async () => { const response = await axios.get('https://jsonplaceholder.typicode.com/posts'); setPosts(response.data); }