msw.test.ts 543 B

12345678910111213141516171819
  1. import { expect, test } from 'vitest'
  2. import { API_URL } from '@/lib/constants'
  3. test('MSW works as expected', async () => {
  4. const res = await fetch(`${API_URL}/msw/test`)
  5. const json = await res.json()
  6. expect(res.status).toBe(200)
  7. expect(json).toEqual({ message: 'Hello from MSW!' })
  8. })
  9. test('MSW errors on missing endpoints', async () => {
  10. expect(async () => {
  11. const res = await fetch(`${API_URL}/endpoint-that-doesnt-exist`)
  12. const json = await res.json()
  13. expect(json).toEqual({ message: '🚫 MSW missed' })
  14. })
  15. })