VITEST
I'm losing my mind trying to understand how to test fetch API functions. I watched all vitest videos in all languages, I read the docs and still I don't get it. Should just memorize one way to test and never change? Because I tried so hard but every video, every blog article says something different. I know the basic concepts (test if it's ok, if it's not ok, if it has network error) but I just can't implement, I don't understand why the stuffs are there in the place, why they exist... I can't even explain better the frustration felling. It shouldn't be this difficult. Can someone give me a "universal fetch api test"? At this point I'm so mentally tired that I just want to ctrl c ctrl v and never care about this anymore. The function I was trying to use with vitest in nextjs 16:
const getPosts = async () => {
const res = await fetch("https://jsonplaceholder.typicode.com/posts")
if (!res.ok) return null
const data = await res.json()
return data
}
export { getPosts }