How do I test my useEffect Fetch with Jest in React? I've tried looking for answers and found a code that I copied to try out but am still failing the test. I haven't used Jest before and am currently trying to implement it in a code I'm working on.
Here is my test inside my test.js file:
it('Displays days from 1 to 31', async () => {
expect(useEffectTest).toBe([{ day: 1 }]);
});
And here is the useEffect in another component called calendar.jsx:
const useEffectTest = () => {
const [daysData, setDaysData] = useState([]);
useEffect(() => {
fetch('http://localhost:5001/chocolates')
.then((resp) => resp.json())
.then((data) => setDaysData(data));
}, []);
console.log(daysData);
};
I want to test if the fetched api is acquiring this data from an array of objects:
{ day: 1, status: 'empty' || 'open' }
Thanks for any help in advance.