I'm learning Jest basically, I have to write a test case for the useEffect() hook which renders based on a flag[counter], and which internally checks if a localStorage value is present for a field.
function sample(props) {
const counter = props;
const [displayIcon, setDisplayIcon] = useState(counter);
function isLocalstoragePresent() {
return localStorage.getItem("some_Id");
}
useEffect(() => {
if (isLocalstoragePresent()) {
setDisplayIcon(true);
} else {
setDisplayIcon(false);
}
}, [counter]);
export default sample;
Can some one help me in writing test case/provide a guidence for the UseEffect which internally calls isLocalstoragePresent() method aswell. Thanks in advance.