u/Disastrous_Lie_6101

▲ 1 r/devBR

vitest

3 dias tentando entender, vi todos vídeos que há no youtube, li a doc, fiz TUDO mas não sei qual o jeito certo de fazer teste para fetch api. Por favor alguém me de o teste completo (que se espera de um fetch api) porque eu já to jogando a toalha, minha sanidade mental tá a beira do colapso. Se puder explicar também linha por linha (eu sei que é pedir DEMAIS) ficarei eternamente agradecido. To usando nextjs 16. Eu só quero ajuda para entender, por favor não sejam escrotos, vocês já passaram por essa fase também.

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 }

resumo: tentei aprender vitest e não consegui, to quase me internando num hospício.

reddit.com
u/Disastrous_Lie_6101 — 9 hours ago
▲ 6 r/react

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 }
reddit.com
u/Disastrous_Lie_6101 — 9 hours ago