Skip to content
Myr

http-exception.test.ts

This file

Path

src/http-exception.test.ts

45 lines · 1.5 KiB · TypeScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than f0b094d point at it.

Merge commit from forkYusuke Wadabefore adoptionf0b094d

lines 1–45why, one step back
1import { HTTPException } from './http-exception'
23describe('HTTPException', () => {4 it('Should be 401 HTTP exception object', async () => {5 // We should throw an exception if is not authorized6 // because next handlers should not be fired.7 const exception = new HTTPException(401, {8 message: 'Unauthorized',9 })10 const res = exception.getResponse()1112 expect(res.status).toBe(401)13 expect(await res.text()).toBe('Unauthorized')14 expect(exception.status).toBe(401)15 expect(exception.message).toBe('Unauthorized')16 })1718 it('Should be accessible to the object causing the exception', async () => {19 // We should pass the cause of the error to the cause option20 // because it makes debugging easier.21 const error = new Error('Server Error')22 const exception = new HTTPException(500, {23 message: 'Internal Server Error',24 cause: error,25 })26 const res = exception.getResponse()2728 expect(res.status).toBe(500)29 expect(await res.text()).toBe('Internal Server Error')30 expect(exception.status).toBe(500)31 expect(exception.message).toBe('Internal Server Error')32 expect(exception.cause).toBe(error)33 })3435 it('Should prioritize the status code over the code in the response', async () => {36 const exception = new HTTPException(400, {37 res: new Response('An exception', {38 status: 200,39 }),40 })41 const res = exception.getResponse()42 expect(res.status).toBe(400)43 expect(await res.text()).toBe('An exception')44 })45})