我基本上正在学习 Jest,我必须为 useEffect() 钩子编写一个测试用例,该钩子基于 flag[counter] 进行渲染,并在内部检查字段是否存在 localStorage 值。
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;
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我编写测试用例/为内部调用 isLocalstoragePresent() 方法的 UseEffect 提供指导吗?提前致谢。