Skip to content

Commit

Permalink
test: add fetch relative url test in jsdom
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Jan 25, 2024
1 parent 17bf9fc commit 9485aea
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/node/rest-api/request/matching/relative-url.node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @vitest-environment jsdom
*/
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'

const server = setupServer(
http.get('/api/movies', () => {
return HttpResponse.json([
{ title: 'The Lord of the Rings' },
{ title: 'The Matrix' },
])
}),
)

beforeAll(() => {
server.listen()
})

afterAll(() => {
server.close()
})

it('responds to a relative URL in jsdom', async () => {
const response = await fetch('/api/movies')

expect(response.status).toBe(200)
expect(await response.json()).toEqual([
{ title: 'The Lord of the Rings' },
{ title: 'The Matrix' },
])
})

0 comments on commit 9485aea

Please sign in to comment.