MCPcopy
hub / github.com/fastify/fastify / helper

Function helper

test/reply-error.test.js:16–47  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

14})
15
16function helper (code) {
17 test('Reply error handling - code: ' + code, (t, testDone) => {
18 t.plan(4)
19 const fastify = Fastify()
20 t.after(() => fastify.close())
21 const err = new Error('winter is coming')
22
23 fastify.get('/', (req, reply) => {
24 reply
25 .code(Number(code))
26 .send(err)
27 })
28
29 fastify.inject({
30 method: 'GET',
31 url: '/'
32 }, (error, res) => {
33 t.assert.ifError(error)
34 t.assert.strictEqual(res.statusCode, Number(code))
35 t.assert.strictEqual(res.headers['content-type'], 'application/json; charset=utf-8')
36 t.assert.deepStrictEqual(
37 {
38 error: statusCodes[code],
39 message: err.message,
40 statusCode: Number(code)
41 },
42 JSON.parse(res.payload)
43 )
44 testDone()
45 })
46 })
47}
48
49test('preHandler hook error handling with external code', (t, testDone) => {
50 t.plan(3)

Callers 1

Calls 5

afterMethod · 0.80
closeMethod · 0.80
sendMethod · 0.80
codeMethod · 0.80
injectMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…