Skip to content

Instantly share code, notes, and snippets.

@mcollina
Last active February 6, 2018 13:49
Show Gist options
  • Save mcollina/33707d38cb01bd2e80fbb9090e343c84 to your computer and use it in GitHub Desktop.
Save mcollina/33707d38cb01bd2e80fbb9090e343c84 to your computer and use it in GitHub Desktop.
test('Register an hook after a plugin', t => {
t.plan(6)
const fastify = Fastify()
fastify.register(fp(function (instance, opts, next) {
instance.addHook('preHandler', function (req, reply, next) {
t.ok('called')
next()
})
fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})
next()
}))
fastify.register(fp(function (instance, opts, next) {
fastify.addHook('preHandler', function (req, reply, next) {
t.ok('called')
next()
})
fastify.addHook('preHandler', function (req, reply, next) {
t.ok('called')
next()
})
next()
}))
fastify.inject({
url: '/',
method: 'GET'
}, (err, res) => {
t.error(err)
t.is(res.statusCode, 200)
t.deepEqual(JSON.parse(res.payload), { hello: 'world' })
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment