-
What's the proper way to test if an exception is thrown in a plugin? async function myPlugin(fastify, config) {
if (config === 'foo') {
throw new Error('foo');
}
fastify.decorate('foo', 'foo');
}
test('Throws foo', () => {
const fastify = Fastify();
// This doesn't work.
expect(() => {
fastify.register(myPlugin, 'foo');
}).toThrow();
}); |
Beta Was this translation helpful? Give feedback.
Answered by
Uzlopak
Feb 7, 2023
Replies: 1 comment 9 replies
-
With tap it would be
You are using mocha/chai. So read the documentation of your test runner on how to test for promises and rejections. |
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
onosendi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With tap it would be
await t.rejects(() => fastify.register(myPlugin, 'foo'), new Error('foo'))
You are using mocha/chai. So read the documentation of your test runner on how to test for promises and rejections.
e.g. https://www.chaijs.com/plugins/chai-as-promised/