Skip to content

Commit

Permalink
test:fix: useSignatureMetrics test
Browse files Browse the repository at this point in the history
  • Loading branch information
digiwand committed Jan 16, 2025
1 parent 7de1a69 commit 4dc981b
Showing 1 changed file with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MetaMetricsEvents } from '../../../../core/Analytics';
import { renderHookWithProvider } from '../../../../util/test/renderWithProvider';
import { useSignatureMetrics } from './useSignatureMetrics';
import { SignatureRequestType, SignatureRequest } from '@metamask/signature-controller';

const mockSigRequest = {
type: 'personal_sign',
type: SignatureRequestType.PersonalSign,
messageParams: {
data: '0x4578616d706c652060706572736f6e616c5f7369676e60206d657373616765',
from: '0x935e73edb9ff52e23bac7f7e043a1ecd06d05477',
Expand All @@ -16,8 +17,8 @@ const mockSigRequest = {
origin: 'metamask.github.io',
metamaskId: '76b33b40-7b5c-11ef-bc0a-25bce29dbc09',
},
chainId: '0x0',
};
chainId: '0x1' as `0x${string}`,
} as const;

jest.mock('./useSignatureRequest', () => ({
useSignatureRequest: () => mockSigRequest,
Expand All @@ -41,7 +42,20 @@ describe('useSignatureMetrics', () => {
});
it('should capture metrics events correctly', async () => {
const { result } = renderHookWithProvider(() => useSignatureMetrics(), {
state: {},
state: {
engine: {
backgroundState: {
PreferencesController: {
useTransactionSimulations: true,
},
SignatureController: {
signatureRequests: {
[mockSigRequest.messageParams.metamaskId]: mockSigRequest,
} as unknown as Record<string, SignatureRequest>,
},
},
},
},
});
// first call for 'SIGNATURE_REQUESTED' event
expect(mockTrackEvent).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit 4dc981b

Please sign in to comment.