@tinytapanalytics/sdk
Version:
Behavioral psychology platform that detects visitor frustration, predicts abandonment, and helps you save at-risk conversions in real-time
60 lines (51 loc) • 1.46 kB
text/typescript
import 'jest-environment-jsdom';
// Mock DOM APIs that might not be available in jsdom
// jsdom provides localStorage by default, no need to mock it
Object.defineProperty(window, 'navigator', {
value: {
sendBeacon: jest.fn(),
language: 'en-US',
languages: ['en-US'],
},
writable: true,
});
Object.defineProperty(window, 'crypto', {
value: {
getRandomValues: jest.fn((arr) => {
for (let i = 0; i < arr.length; i++) {
arr[i] = Math.floor(Math.random() * 256);
}
return arr;
}),
},
writable: true,
});
// Mock fetch API
global.fetch = jest.fn();
// Mock IntersectionObserver
global.IntersectionObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
// Mock ResizeObserver
global.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
// Mock MutationObserver
global.MutationObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
disconnect: jest.fn(),
}));
// Mock URL.createObjectURL
global.URL.createObjectURL = jest.fn();
// Silence console warnings in tests unless we're specifically testing them
const originalConsoleWarn = console.warn;
console.warn = (...args) => {
if (args[0]?.includes && args[0].includes('TinyTapAnalytics')) {
return; // Silence our own warnings in tests
}
originalConsoleWarn(...args);
};