testExecutionHook() — fastify Function Reference
Architecture documentation for the testExecutionHook() function in route-hooks.test.js from the fastify codebase.
Entity Profile
Dependency Diagram
graph TD e03539a9_ae42_6f97_fd24_e70e0ae77a54["testExecutionHook()"] 20e9500e_9530_50df_e580_26d847082774["route-hooks.test.js"] e03539a9_ae42_6f97_fd24_e70e0ae77a54 -->|defined in| 20e9500e_9530_50df_e580_26d847082774 1423a7ac_9338_cc04_41d6_66f0234eced2["endRouteHook()"] e03539a9_ae42_6f97_fd24_e70e0ae77a54 -->|calls| 1423a7ac_9338_cc04_41d6_66f0234eced2 style e03539a9_ae42_6f97_fd24_e70e0ae77a54 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
test/route-hooks.test.js lines 17–180
function testExecutionHook (hook) {
test(`${hook}`, (t, testDone) => {
t.plan(3)
const fastify = Fastify()
fastify.post('/', {
[hook]: (req, reply, doneOrPayload, done) => {
t.assert.ok('hook called')
endRouteHook(doneOrPayload, done)
}
}, (req, reply) => {
reply.send(req.body)
})
fastify.inject({
method: 'POST',
url: '/',
payload: { hello: 'world' }
}, (err, res) => {
t.assert.ifError(err)
const payload = JSON.parse(res.payload)
t.assert.deepStrictEqual(payload, { hello: 'world' })
testDone()
})
})
test(`${hook} option should be called after ${hook} hook`, (t, testDone) => {
t.plan(3)
const fastify = Fastify()
const checker = Object.defineProperty({ calledTimes: 0 }, 'check', {
get: function () { return ++this.calledTimes }
})
fastify.addHook(hook, (req, reply, doneOrPayload, done) => {
t.assert.strictEqual(checker.check, 1)
endRouteHook(doneOrPayload, done)
})
fastify.post('/', {
[hook]: (req, reply, doneOrPayload, done) => {
t.assert.strictEqual(checker.check, 2)
endRouteHook(doneOrPayload, done)
}
}, (req, reply) => {
reply.send({})
})
fastify.inject({
method: 'POST',
url: '/',
payload: { hello: 'world' }
}, (err, res) => {
t.assert.ifError(err)
testDone()
})
})
test(`${hook} option could accept an array of functions`, (t, testDone) => {
t.plan(3)
const fastify = Fastify()
const checker = Object.defineProperty({ calledTimes: 0 }, 'check', {
get: function () { return ++this.calledTimes }
})
fastify.post('/', {
[hook]: [
(req, reply, doneOrPayload, done) => {
t.assert.strictEqual(checker.check, 1)
endRouteHook(doneOrPayload, done)
},
(req, reply, doneOrPayload, done) => {
t.assert.strictEqual(checker.check, 2)
endRouteHook(doneOrPayload, done)
}
]
}, (req, reply) => {
reply.send({})
})
fastify.inject({
method: 'POST',
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does testExecutionHook() do?
testExecutionHook() is a function in the fastify codebase, defined in test/route-hooks.test.js.
Where is testExecutionHook() defined?
testExecutionHook() is defined in test/route-hooks.test.js at line 17.
What does testExecutionHook() call?
testExecutionHook() calls 1 function(s): endRouteHook.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free