Skip to content

Commit

Permalink
add relative url test to with-jest-jsdom (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Mar 2, 2024
1 parent 6bd9453 commit d3c1575
Show file tree
Hide file tree
Showing 5 changed files with 1,432 additions and 263 deletions.
50 changes: 0 additions & 50 deletions examples/with-jest-jsdom/example-jsdom.test.ts

This file was deleted.

12 changes: 11 additions & 1 deletion examples/with-jest-jsdom/example.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @jest-environment node
* @jest-environment jsdom
*/

it('receives a mocked response to a REST API request', async () => {
Expand All @@ -13,6 +13,16 @@ it('receives a mocked response to a REST API request', async () => {
})
})

it('receives a mocked response to a REST API requets to a relative URL', async () => {
const response = await fetch('/product')

expect(response.status).toBe(200)
expect(response.statusText).toBe('OK')
expect(await response.json()).toEqual({
name: 'Awesome Product',
})
})

it('receives a mocked response to a GraphQL API request', async () => {
const response = await fetch('https://api.example.com/graphql', {
method: 'POST',
Expand Down
5 changes: 5 additions & 0 deletions examples/with-jest-jsdom/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export const handlers = [
lastName: 'Maverick',
})
}),
http.get('/product', () => {
return HttpResponse.json({
name: 'Awesome Product',
})
}),
graphql.query('ListMovies', () => {
return HttpResponse.json({
data: {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-jest-jsdom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@types/node": "^18",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"msw": "2.0.14",
"msw": "2.2.2",
"ts-node": "^10.9.2",
"typescript": "^5.0.4",
"undici": "^5.22.0"
Expand Down
Loading

0 comments on commit d3c1575

Please sign in to comment.