Last active
February 6, 2018 13:49
-
-
Save mcollina/33707d38cb01bd2e80fbb9090e343c84 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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