honojs-middleware/test/index.test.ts

29 lines
827 B
TypeScript
Raw Normal View History

2022-08-04 07:54:30 +08:00
import { Hono } from 'hono'
2022-08-04 07:33:14 +08:00
import { sentry } from '../src'
2022-08-04 07:54:30 +08:00
const captureException = jest.fn()
jest.mock('toucan-js', () => jest.fn().mockImplementation(() => ({ captureException })))
2022-08-04 07:33:14 +08:00
describe('Sentry middleware', () => {
2022-08-04 07:54:30 +08:00
const app = new Hono()
app.use('/sentry/*', sentry())
app.get('/sentry/foo', (c) => c.text('foo'))
app.get('/sentry/error', () => {
throw new Error('a catastrophic error')
})
2022-08-04 07:54:30 +08:00
2022-08-04 07:33:14 +08:00
it('Should initialize Toucan', async () => {
const res = await app.request('http://localhost/sentry/foo')
2022-08-04 07:54:30 +08:00
expect(res).not.toBeNull()
expect(res.status).toBe(200)
})
it('Should report errors', async () => {
const res = await app.request('http://localhost/sentry/error')
expect(res).not.toBeNull()
expect(res.status).toBe(500)
expect(captureException).toHaveBeenCalled()
})
2022-08-04 07:54:30 +08:00
})