mirror of
https://github.com/selfxyz/self.git
synced 2026-02-19 02:24:25 -05:00
SELF-773: standardize analytics imports (#1538)
* standardize analytics * format
This commit is contained in:
@@ -19,6 +19,9 @@ jest.mock('@/services/analytics', () => ({
|
||||
trackScreenView: jest.fn(),
|
||||
flush: jest.fn(),
|
||||
})),
|
||||
trackEvent: jest.fn(),
|
||||
trackScreenView: jest.fn(),
|
||||
flush: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('navigation', () => {
|
||||
|
||||
@@ -11,16 +11,20 @@ import {
|
||||
checkAndUpdateRegistrationStates,
|
||||
getAlternativeCSCA,
|
||||
} from '@/proving/validateDocument';
|
||||
import analytics from '@/services/analytics';
|
||||
import { trackEvent } from '@/services/analytics';
|
||||
|
||||
// Mock the analytics module to avoid side effects in tests
|
||||
jest.mock('@/services/analytics', () => {
|
||||
// Create mock inside factory to avoid temporal dead zone
|
||||
const mockTrackEvent = jest.fn();
|
||||
return jest.fn(() => ({
|
||||
trackEvent: mockTrackEvent,
|
||||
}));
|
||||
});
|
||||
jest.mock('@/services/analytics', () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(() => ({
|
||||
trackEvent: jest.fn(),
|
||||
trackScreenView: jest.fn(),
|
||||
flush: jest.fn(),
|
||||
})),
|
||||
trackEvent: jest.fn(),
|
||||
trackScreenView: jest.fn(),
|
||||
flush: jest.fn(),
|
||||
}));
|
||||
|
||||
// Mock the passport data provider to avoid database operations
|
||||
const mockGetAllDocumentsDirectlyFromKeychain = jest.fn();
|
||||
@@ -153,8 +157,7 @@ describe('getAlternativeCSCA', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
// Get the mocked trackEvent from the analytics module
|
||||
const mockAnalytics = jest.mocked(analytics);
|
||||
mockTrackEvent = mockAnalytics().trackEvent as jest.Mock;
|
||||
mockTrackEvent = jest.mocked(trackEvent) as jest.Mock;
|
||||
});
|
||||
|
||||
it('should return public keys in Record format for Aadhaar with valid public keys', () => {
|
||||
@@ -245,8 +248,7 @@ describe('checkAndUpdateRegistrationStates', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
// Get the mocked trackEvent from the analytics module
|
||||
const mockAnalytics = jest.mocked(analytics);
|
||||
mockTrackEvent = mockAnalytics().trackEvent as jest.Mock;
|
||||
mockTrackEvent = jest.mocked(trackEvent) as jest.Mock;
|
||||
|
||||
mockGetState.mockReturnValue(
|
||||
buildState({
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
|
||||
|
||||
import analytics from '@/services/analytics';
|
||||
import { trackEvent, trackScreenView } from '@/services/analytics';
|
||||
|
||||
// Mock the Segment client
|
||||
jest.mock('@/config/segment', () => ({
|
||||
@@ -13,8 +13,6 @@ jest.mock('@/config/segment', () => ({
|
||||
}));
|
||||
|
||||
describe('analytics', () => {
|
||||
const { trackEvent, trackScreenView } = analytics();
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user