问题
How can I test the useEffect
for one time call, so I am loading a number of links on mount. so it will be called only once
see the code
app.js
import React, { useState, useEffect } from "react";
const App = () => {
const [links, setLinks] = useState([]);
useEffect(() => {
const links = createLinks();
setLinks(links);
}, []);
const createLinks = () => {
return [{ link: "https://www.google.com", text: "Google" }];
};
return <>{links.length && links.map(({ link, text }) => <a href={link}>{text}</a>)}</>;
};
export default App
how can i write a test case for the above sample app component using jest and enzyme
来源:https://stackoverflow.com/questions/59169619/using-jest-and-enzyme-testing-useeffect-and-usestate