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

Function helper

test/reply-error.test.js:16–47  ·  test/reply-error.test.js::helper
(code)

Source from the content-addressed store, hash-verified

14})
15
16function helper (code) {
17 test(class="st">'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(class="st">'winter is coming')
22
23 fastify.get(class="st">'/', (req, reply) => {
24 reply
25 .code(Number(code))
26 .send(err)
27 })
28
29 fastify.inject({
30 method: class="st">'GET',
31 url: class="st">'/'
32 }, (error, res) => {
33 t.assert.ifError(error)
34 t.assert.strictEqual(res.statusCode, Number(code))
35 t.assert.strictEqual(res.headers[class="st">'content-type'], class="st">'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(class="st">'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