apps/admin/test-utils/analytics/README.md
This directory contains utilities to improve test reliability and consistency across the analytics test suite.
test-helpers.tsProvides setupStatsAppMocks(), a universal mock setup for stats hooks. It returns
pre-configured mock functions for the stats API hooks and the analytics context,
seeded with the centralized responseFixtures from @tryghost/admin-x-framework/test/acceptance.
Usage:
import { setupStatsAppMocks } from '@test-utils/analytics/test-helpers';
beforeEach(() => {
const mocks = setupStatsAppMocks();
});
date-testing-utils.tsPurpose: Eliminate date-related test flakiness
Key Features:
2024-01-15T12:00:00.000Z) for consistent test behaviorUsage:
import { setupDateMocking, getExpectedDateRange } from '@test-utils/analytics/date-testing-utils';
beforeEach(() => {
const dateMocking = setupDateMocking();
});
// Use consistent date ranges in assertions
const { expectedDateFrom, expectedDateTo } = getExpectedDateRange(30);
setupStatsAppMocks when a test needs the standard stats hook mocksmockApiHook, mockSuccess, mockLoading, ...),
import from @tryghost/admin-x-framework/test/hook-testing-utils