Files
freeCodeCamp/api/src/plugins/growth-book.test.ts
Oliver Eyton-Williams 37028f2bb8 chore(api): log growthbook initialization failures (#59889)
Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
2025-04-22 18:36:27 +02:00

30 lines
748 B
TypeScript

import Fastify, { type FastifyInstance } from 'fastify';
import growthBook from './growth-book';
const captureException = jest.fn();
describe('growth-book', () => {
let fastify: FastifyInstance;
beforeAll(() => {
fastify = Fastify();
// @ts-expect-error we're mocking the Sentry plugin
fastify.Sentry = { captureException };
});
afterAll(async () => {
await fastify.close();
});
it('should log the error if the GrowthBook initialization fails', async () => {
const spy = jest.spyOn(fastify.log, 'error');
await fastify.register(growthBook, {
apiHost: 'invalid-url',
clientKey: 'invalid-key'
});
expect(spy).toHaveBeenCalled();
expect(captureException).toHaveBeenCalled();
});
});