1- import { type PartialMockedFunction } from '@app/test-utils'
2-
3- import { PartiallyMockedFunction } from '@vitest/spy'
4- import { WaitForTransactionReceiptReturnType } from 'viem'
1+ import { type MockedFunctionDeep } from '@vitest/spy'
2+ import { WaitForTransactionReceiptReturnType , type Transaction } from 'viem'
53import { waitForTransactionReceipt } from 'viem/actions'
6- import { describe , expect , it , vi } from 'vitest'
4+ import { beforeEach , describe , expect , it , vi } from 'vitest'
75
86import { ClientWithEns , ConfigWithEns } from '@app/types'
97import { fetchTxFromSafeTxHash } from '@app/utils/safe'
@@ -14,11 +12,10 @@ vi.mock('viem/actions')
1412
1513vi . mock ( '@app/utils/safe' )
1614
17- const mockWaitForTransactionReceipt = waitForTransactionReceipt as unknown as PartialMockedFunction <
15+ const mockWaitForTransactionReceipt = waitForTransactionReceipt as MockedFunctionDeep <
1816 typeof waitForTransactionReceipt
1917>
20-
21- const mockFetchTxFromSafeTxHash = fetchTxFromSafeTxHash as unknown as PartiallyMockedFunction <
18+ const mockFetchTxFromSafeTxHash = fetchTxFromSafeTxHash as MockedFunctionDeep <
2219 typeof fetchTxFromSafeTxHash
2320>
2421
@@ -50,6 +47,10 @@ const mockTransactionReceiptData: WaitForTransactionReceiptReturnType = {
5047 type : 'legacy' ,
5148}
5249
50+ beforeEach ( ( ) => {
51+ vi . clearAllMocks ( )
52+ } )
53+
5354describe ( 'waitForTransaction' , ( ) => {
5455 it ( 'should wait for standard transaction' , async ( ) => {
5556 // @ts -ignore vi.fn is messing with types
@@ -62,7 +63,6 @@ describe('waitForTransaction', () => {
6263 expect ( result ) . toStrictEqual ( mockTransactionReceiptData )
6364 } )
6465 it ( 'should pass onReplaced tx to waitForTransactionReceipt' , async ( ) => {
65- // @ts -ignore vi.fn is messing with types
6666 mockWaitForTransactionReceipt . mockResolvedValueOnce ( mockTransactionReceiptData )
6767
6868 const onReplaced = vi . fn ( )
@@ -72,12 +72,22 @@ describe('waitForTransaction', () => {
7272 onReplaced,
7373 } )
7474
75- expect ( mockWaitForTransactionReceipt ) . toHaveBeenCalledWith (
76- mockClient ,
77- expect . objectContaining ( {
78- onReplaced,
79- } ) ,
80- )
75+ expect ( mockWaitForTransactionReceipt ) . toHaveBeenCalled ( )
76+
77+ const onReplacedInternalFn = mockWaitForTransactionReceipt . mock . calls [ 0 ] [ 1 ] . onReplaced
78+ onReplacedInternalFn ! ( {
79+ reason : 'replaced' ,
80+ transaction : {
81+ hash : '0xnewhash' ,
82+ } as unknown as Transaction ,
83+ replacedTransaction : { } as unknown as Transaction ,
84+ transactionReceipt : { } as unknown as WaitForTransactionReceiptReturnType ,
85+ } )
86+
87+ expect ( onReplaced ) . toHaveBeenCalledWith ( {
88+ reason : 'replaced' ,
89+ transactionHash : '0xnewhash' ,
90+ } )
8191 } )
8292} )
8393
0 commit comments