Skip to content

Commit

Permalink
chore: use "res.allHeaders()" instead of "res.headers()"
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Oct 30, 2021
1 parent 095de1b commit f6fbd6c
Show file tree
Hide file tree
Showing 31 changed files with 65 additions and 63 deletions.
2 changes: 1 addition & 1 deletion test/graphql-api/cookies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('sets cookie on the mocked GraphQL response', async () => {
`,
})

const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
6 changes: 3 additions & 3 deletions test/graphql-api/document-node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('intercepts a GraphQL query based on its DocumentNode', async () => {
})

expect(res.status()).toEqual(200)
expect(res.headers()).toHaveProperty('x-powered-by', 'msw')
expect(await res.allHeaders()).toHaveProperty('x-powered-by', 'msw')

const json = await res.json()
expect(json).toEqual({
Expand Down Expand Up @@ -52,7 +52,7 @@ test('intercepts a GraphQL mutation based on its DocumentNode', async () => {
})

expect(res.status()).toEqual(200)
expect(res.headers()).toHaveProperty('x-powered-by', 'msw')
expect(await res.allHeaders()).toHaveProperty('x-powered-by', 'msw')

const json = await res.json()
expect(json).toEqual({
Expand Down Expand Up @@ -87,7 +87,7 @@ test('intercepts a scoped GraphQL query based on its DocumentNode', async () =>
)

expect(res.status()).toEqual(200)
expect(res.headers()).toHaveProperty('x-powered-by', 'msw')
expect(await res.allHeaders()).toHaveProperty('x-powered-by', 'msw')

const json = await res.json()
expect(json).toEqual({
Expand Down
6 changes: 3 additions & 3 deletions test/graphql-api/link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('mocks a GraphQL query to the GitHub GraphQL API', async () => {
},
)

const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toEqual(200)
Expand Down Expand Up @@ -73,7 +73,7 @@ test('mocks a GraphQL mutation to the Stripe GraphQL API', async () => {
},
)

const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toEqual(200)
Expand Down Expand Up @@ -104,7 +104,7 @@ test('falls through to the matching GraphQL operation to an unknown endpoint', a
},
})

const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-request-handler', 'fallback')
Expand Down
2 changes: 1 addition & 1 deletion test/graphql-api/mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('sends a mocked response to a GraphQL mutation', async () => {
}
`,
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toEqual(200)
Expand Down
4 changes: 2 additions & 2 deletions test/graphql-api/operation-reference.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test('allows referencing the request body in the request handler', async () => {
id: 'abc-123',
},
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down Expand Up @@ -53,7 +53,7 @@ test('allows referencing the request body in the request handler', async () => {
password: 'super-secret',
},
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
8 changes: 4 additions & 4 deletions test/graphql-api/operation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test('intercepts and mocks a GraphQL query', async () => {
id: 'abc-123',
},
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toEqual(200)
Expand Down Expand Up @@ -73,7 +73,7 @@ test('intercepts and mocks an anonymous GraphQL query', async () => {

expect(res.status()).toEqual(200)

const headers = res.headers()
const headers = await res.allHeaders()
expect(headers).toHaveProperty('x-powered-by', 'msw')

const body = await res.json()
Expand Down Expand Up @@ -109,7 +109,7 @@ test('intercepts and mocks a GraphQL mutation', async () => {
password: 'super-secret',
},
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toEqual(200)
Expand Down Expand Up @@ -163,7 +163,7 @@ test('bypasses seemingly compatible REST requests', async () => {
},
)

const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toBe(200)
Expand Down
4 changes: 2 additions & 2 deletions test/graphql-api/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test('mocks a GraphQL query issued with a GET request', async () => {
},
)

const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toEqual(200)
Expand Down Expand Up @@ -59,7 +59,7 @@ test('mocks a GraphQL query issued with a POST request', async () => {
}
`,
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toEqual(200)
Expand Down
4 changes: 2 additions & 2 deletions test/msw-api/context/async-response-transformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('supports asynchronous response transformer', async () => {
path.resolve(__dirname, '../../fixtures/image.jpg'),
)
const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()

expect(status).toBe(201)
expect(headers).toHaveProperty('content-type', 'image/jpeg')
Expand All @@ -34,7 +34,7 @@ test('supports asynchronous default response transformer', async () => {
})
const status = res.status()
const statusText = res.statusText()
const headers = res.headers()
const headers = await res.allHeaders()

expect(status).toBe(301)
expect(statusText).toBe('Custom Status Text')
Expand Down
6 changes: 3 additions & 3 deletions test/msw-api/context/delay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('uses explicit server response delay', async () => {
expect(responseTime).toRoughlyEqual(1200, 250)

const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand All @@ -74,7 +74,7 @@ test('uses realistic server response delay when no delay value is provided', asy
expect(responseTime).toRoughlyEqual(250, 200)

const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand All @@ -96,7 +96,7 @@ test('uses realistic server response delay when "real" delay mode is provided',
expect(responseTime).toRoughlyEqual(250, 200)

const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
2 changes: 1 addition & 1 deletion test/msw-api/exception-handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test('transforms uncaught exceptions into a 500 response', async () => {

const res = await runtime.request('https://api.github.com/users/octocat')
const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(status).toEqual(500)
Expand Down
2 changes: 1 addition & 1 deletion test/msw-api/hard-reload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('keeps the mocking enabled after hard-reload of the page', async () => {
})

const res = await runtime.request('https://api.github.com')
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
4 changes: 2 additions & 2 deletions test/msw-api/integrity-check.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('activates the worker without errors given the latest integrity', async ()
expect(consoleSpy.get('error')).toBeUndefined()

const res = await request('https://api.github.com/users/octocat')
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down Expand Up @@ -63,7 +63,7 @@ test('errors when activating the worker with an outdated integrity', async () =>

// Should still keep the mocking enabled.
const res = await request('https://api.github.com/users/octocat')
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
2 changes: 1 addition & 1 deletion test/msw-api/setup-worker/start/quiet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('does not log the captured request when the "quiet" option is set to "true"

const res = await request('/user')

const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
4 changes: 2 additions & 2 deletions test/msw-api/setup-worker/stop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('disables the mocking when the worker is stopped', async () => {
await stopWorkerOn(runtime.page)

const res = await runtime.request('https://api.github.com')
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).not.toHaveProperty('x-powered-by', 'msw')
Expand Down Expand Up @@ -56,7 +56,7 @@ test('keeps the mocking enabled in one tab when stopping the worker in another t
// Create a request handler for the new page.
const request = createRequestUtil(secondPage, server)
const res = await request('https://api.github.com')
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
3 changes: 2 additions & 1 deletion test/rest-api/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ test('mocks response to a basic GET request', async () => {
})

const res = await runtime.request('https://api.github.com/users/octocat')
const headers = await res.allHeaders()
const body = await res.json()

expect(res.headers()).toHaveProperty('x-powered-by', 'msw')
expect(res.status()).toBe(200)
expect(headers).toHaveProperty('x-powered-by', 'msw')
expect(body).toEqual({
name: 'John Maverick',
originalUsername: 'octocat',
Expand Down
2 changes: 1 addition & 1 deletion test/rest-api/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test('composes various context utilities into a valid mocked response', async ()
})

const res = await runtime.request('https://test.mswjs.io/')
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(res.status()).toEqual(201)
Expand Down
8 changes: 4 additions & 4 deletions test/rest-api/cookies-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('returns all document cookies in "req.cookies" for "include" credentials',
const res = await runtime.request('/user', {
credentials: 'include',
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand All @@ -36,7 +36,7 @@ test('returns all document cookies in "req.cookies" for "same-origin" credential
const res = await runtime.request('/user', {
credentials: 'same-origin',
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand All @@ -54,7 +54,7 @@ test('returns no cookies in "req.cookies" for "same-origin" credentials and requ
const res = await runtime.request('https://test.mswjs.io/user', {
credentials: 'same-origin',
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand All @@ -69,7 +69,7 @@ test('returns no cookies in "req.cookies" for "omit" credentials', async () => {
const res = await runtime.request('/user', {
credentials: 'omit',
})
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
2 changes: 1 addition & 1 deletion test/rest-api/cookies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('allows setting cookies on the mocked response', async () => {

const res = await runtime.request('/user')

const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
4 changes: 2 additions & 2 deletions test/rest-api/custom-request-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('intercepts a request with a custom request handler with default context',
},
})
const body = await res.json()
const headers = res.headers()
const headers = await res.allHeaders()

expect(res.status()).toBe(401)
expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand All @@ -30,7 +30,7 @@ test('intercepts a request with a custom request handler with custom context', a

const res = await runtime.request('https://test.url/')
const body = await res.json()
const headers = res.headers()
const headers = await res.allHeaders()

expect(res.status()).toBe(200)
expect(headers).toHaveProperty('x-powered-by', 'msw')
Expand Down
4 changes: 2 additions & 2 deletions test/rest-api/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('supports a generator function as the response resolver', async () => {
const assertRequest = async (expectedBody: ExpectedResponseBody) => {
const res = await runtime.request('/polling/3')
const body = await res.json()
expect(res.headers()).toHaveProperty('x-powered-by', 'msw')
expect(await res.allHeaders()).toHaveProperty('x-powered-by', 'msw')
expect(res.status()).toBe(200)
expect(body).toEqual(expectedBody)
}
Expand All @@ -39,7 +39,7 @@ test('supports one-time handlers with the generator as the response resolver', a
const assertRequest = async (expectedBody: ExpectedResponseBody) => {
const res = await runtime.request('/polling/once/3')
const body = await res.json()
expect(res.headers()).toHaveProperty('x-powered-by', 'msw')
expect(await res.allHeaders()).toHaveProperty('x-powered-by', 'msw')
expect(res.status()).toBe(200)
expect(body).toEqual(expectedBody)
}
Expand Down
2 changes: 1 addition & 1 deletion test/rest-api/headers-multiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('supports setting a header with multiple values on the mocked response', as

const res = await runtime.request('https://test.mswjs.io')
const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(status).toEqual(200)
Expand Down
2 changes: 1 addition & 1 deletion test/rest-api/params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('parses request URL parameters', async () => {
'https://api.github.com/users/octocat/messages/abc-123',
)
const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(status).toBe(200)
Expand Down
4 changes: 2 additions & 2 deletions test/rest-api/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('retrieves a single request URL query parameter', async () => {
'https://test.mswjs.io/api/books?id=abc-123',
)
const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(status).toBe(200)
Expand All @@ -34,7 +34,7 @@ test('retrieves multiple request URL query parameters', async () => {
},
)
const status = res.status()
const headers = res.headers()
const headers = await res.allHeaders()
const body = await res.json()

expect(status).toBe(200)
Expand Down
Loading

0 comments on commit f6fbd6c

Please sign in to comment.