Sha256: e91c21c324ea0cbaf04f4ece5d30b461d4967cf08c7ca7a6219c77ba745d21a4
Contents?: true
Size: 1.82 KB
Versions: 26
Compression:
Stored size: 1.82 KB
Contents
/** * @vitest-environment node */ import { http } from './http' import { getResponse } from './getResponse' it('returns undefined given empty headers array', async () => { expect( await getResponse([], new Request('http://localhost/')), ).toBeUndefined() }) it('returns undefined given no matching handlers', async () => { expect( await getResponse( [http.get('/product', () => void 0)], new Request('http://localhost/user'), ), ).toBeUndefined() }) it('returns undefined given a matching handler that returned no response', async () => { expect( await getResponse( [http.get('*/user', () => void 0)], new Request('http://localhost/user'), ), ).toBeUndefined() }) it('returns undefined given a matching handler that returned explicit undefined', async () => { expect( await getResponse( [http.get('*/user', () => undefined)], new Request('http://localhost/user'), ), ).toBeUndefined() }) it('returns the response returned from a matching handler', async () => { const response = await getResponse( [http.get('*/user', () => Response.json({ name: 'John' }))], new Request('http://localhost/user'), ) expect(response?.status).toBe(200) expect(response?.headers.get('Content-Type')).toBe('application/json') expect(await response?.json()).toEqual({ name: 'John' }) }) it('returns the response from the first matching handler if multiple match', async () => { const response = await getResponse( [ http.get('*/user', () => Response.json({ name: 'John' })), http.get('*/user', () => Response.json({ name: 'Kate' })), ], new Request('http://localhost/user'), ) expect(response?.status).toBe(200) expect(response?.headers.get('Content-Type')).toBe('application/json') expect(await response?.json()).toEqual({ name: 'John' }) })
Version data entries
26 entries across 26 versions & 1 rubygems