Mock Toucan module, check captureException call
parent
855ce4eba4
commit
ca0954a310
|
@ -1,15 +1,28 @@
|
||||||
import { Hono } from 'hono'
|
import { Hono } from 'hono'
|
||||||
import { sentry } from '../src'
|
import { sentry } from '../src'
|
||||||
|
|
||||||
|
const captureException = jest.fn()
|
||||||
|
jest.mock('toucan-js', () => jest.fn().mockImplementation(() => ({ captureException })))
|
||||||
|
|
||||||
describe('Sentry middleware', () => {
|
describe('Sentry middleware', () => {
|
||||||
const app = new Hono()
|
const app = new Hono()
|
||||||
|
|
||||||
app.use('/hello/*', sentry())
|
app.use('/sentry/*', sentry())
|
||||||
app.get('/hello/foo', (c) => c.text('foo'))
|
app.get('/sentry/foo', (c) => c.text('foo'))
|
||||||
|
app.get('/sentry/error', () => {
|
||||||
|
throw new Error('a catastrophic error')
|
||||||
|
})
|
||||||
|
|
||||||
it('Should initialize Toucan', async () => {
|
it('Should initialize Toucan', async () => {
|
||||||
const res = await app.request('http://localhost/hello/foo')
|
const res = await app.request('http://localhost/sentry/foo')
|
||||||
expect(res).not.toBeNull()
|
expect(res).not.toBeNull()
|
||||||
expect(res.status).toBe(200)
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue