Re-Importing modules to avoid init pollution between test runs
import type { BotDetectionResult } from '@fingerprintjs/botd';
import { datadogRum } from '@datadog/browser-rum';
const datadogRumMock = {
setGlobalContextProperty: vi.spyOn(datadogRum, 'setGlobalContextProperty'),
addError: vi.spyOn(datadogRum, 'addError'),
};
describe('_checkForBotsAndReportMetrics...', () => {
let _checkForBotsAndReportMetrics: typeof import('./index')._checkForBotsAndReportMetrics;
let obs: typeof import('@/observability/client/obs').obs;
let emitSpy: MockInstance<typeof obs.emit>;
beforeEach(async () => {
vi.resetModules();
vi.clearAllMocks();
vi.doUnmock('@fingerprintjs/botd');
({ _checkForBotsAndReportMetrics } = await import('./index'));
({ obs } = await import('@/observability/client/obs'));
emitSpy = vi.spyOn(obs, 'emit');
});
vi.doMock('@fingerprintjs/botd', () => ({
load: async () => ({
detect: (): BotDetectionResult => ({
bot: false,
}),
}),
}));