@@ -19,7 +19,7 @@ import {
1919} from '../../../../../../test/data/confirmations/personal_sign' ;
2020import { permitSignatureMsg } from '../../../../../../test/data/confirmations/typed_sign' ;
2121import mockState from '../../../../../../test/data/mock-state.json' ;
22- import { fireEvent , waitFor } from '../../../../../../test/jest' ;
22+ import { fireEvent } from '../../../../../../test/jest' ;
2323import { renderWithConfirmContextProvider } from '../../../../../../test/lib/confirmations/render-helpers' ;
2424import { Alert } from '../../../../../ducks/confirm-alerts/confirm-alerts' ;
2525import { Severity } from '../../../../../helpers/constants/design-system' ;
@@ -37,23 +37,9 @@ import Footer from './footer';
3737jest . mock ( '../../../hooks/gas/useIsGaslessLoading' ) ;
3838jest . mock ( '../../../hooks/alerts/transactions/useInsufficientBalanceAlerts' ) ;
3939jest . mock ( '../../../hooks/gas/useIsGaslessSupported' ) ;
40-
41- // eslint-disable-next-line @typescript-eslint/no-explicit-any
42- let mockStore : any = null ;
43-
44- // eslint-disable-next-line @typescript-eslint/no-explicit-any
45- const mockDispatch : any = jest . fn ( ( action : unknown ) => {
46- if ( typeof action === 'function' ) {
47- // Thunk actions need both dispatch and getState
48- const mockGetState = mockStore ? mockStore . getState : jest . fn ( ( ) => ( { } ) ) ;
49- return action ( mockDispatch , mockGetState ) ;
50- }
51- return action ;
52- } ) ;
53-
5440jest . mock ( 'react-redux' , ( ) => ( {
5541 ...jest . requireActual ( 'react-redux' ) ,
56- useDispatch : ( ) => mockDispatch ,
42+ useDispatch : ( ) => jest . fn ( ) ,
5743} ) ) ;
5844jest . mock ( '../../../hooks/useConfirmationNavigation' , ( ) => ( {
5945 useConfirmationNavigation : jest . fn ( ( ) => ( {
@@ -73,32 +59,13 @@ jest.mock(
7359) ;
7460
7561jest . mock ( '../../../hooks/useOriginThrottling' ) ;
76- jest . mock ( '../../../hooks/useAddEthereumChain' , ( ) => ( {
77- useAddEthereumChain : jest . fn ( ( ) => ( {
78- onSubmit : jest . fn ( ) . mockResolvedValue ( undefined ) ,
79- } ) ) ,
80- isAddEthereumChainType : jest . fn (
81- ( confirmation ) => confirmation ?. type === 'wallet_addEthereumChain' ,
82- ) ,
83- } ) ) ;
84- jest . mock ( '../../../hooks/transactions/useTransactionConfirm' , ( ) => ( {
85- useTransactionConfirm : jest . fn ( ( ) => ( {
86- onTransactionConfirm : jest . fn ( ) . mockResolvedValue ( undefined ) ,
87- } ) ) ,
88- } ) ) ;
89- jest . mock ( '../../../hooks/useConfirmSendNavigation' , ( ) => ( {
90- useConfirmSendNavigation : jest . fn ( ( ) => ( {
91- navigateBackIfSend : jest . fn ( ) ,
92- } ) ) ,
93- } ) ) ;
9462
9563jest . mock ( 'react-router-dom-v5-compat' , ( ) => ( {
9664 useNavigate : jest . fn ( ) ,
9765} ) ) ;
9866
9967const render = ( args ?: Record < string , unknown > ) => {
10068 const store = configureStore ( args ?? getMockPersonalSignConfirmState ( ) ) ;
101- mockStore = store ;
10269
10370 return renderWithConfirmContextProvider ( < Footer /> , store ) ;
10471} ;
@@ -121,10 +88,6 @@ describe('ConfirmFooter', () => {
12188 const useConfirmationNavigationMock = jest . mocked ( useConfirmationNavigation ) ;
12289
12390 beforeEach ( ( ) => {
124- jest . clearAllMocks ( ) ;
125- mockDispatch . mockClear ( ) ;
126- mockStore = null ;
127-
12891 mockUseOriginThrottling . mockReturnValue ( {
12992 shouldThrottleOrigin : false ,
13093 } ) ;
@@ -271,62 +234,50 @@ describe('ConfirmFooter', () => {
271234 } ) ;
272235 } ) ;
273236
274- it ( 'invoke required actions when cancel button is clicked' , async ( ) => {
237+ it ( 'invoke required actions when cancel button is clicked' , ( ) => {
275238 const { getAllByRole } = render ( ) ;
276239 const cancelButton = getAllByRole ( 'button' ) [ 0 ] ;
277240 const rejectSpy = jest
278241 . spyOn ( Actions , 'rejectPendingApproval' )
279242 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31973
280243 // eslint-disable-next-line @typescript-eslint/no-explicit-any
281- . mockImplementation ( ( ) => Promise . resolve ( ) as any ) ;
244+ . mockImplementation ( ( ) => ( { } ) as any ) ;
282245 const updateCustomNonceSpy = jest
283246 . spyOn ( Actions , 'updateCustomNonce' )
284247 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31973
285248 // eslint-disable-next-line @typescript-eslint/no-explicit-any
286- . mockReturnValue ( { } as any ) ;
249+ . mockImplementation ( ( ) => ( { } ) as any ) ;
287250 const setNextNonceSpy = jest
288251 . spyOn ( Actions , 'setNextNonce' )
289252 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31973
290253 // eslint-disable-next-line @typescript-eslint/no-explicit-any
291- . mockReturnValue ( { } as any ) ;
292-
254+ . mockImplementation ( ( ) => ( { } ) as any ) ;
293255 fireEvent . click ( cancelButton ) ;
294-
295- // Wait for async onCancel to complete
296- await waitFor ( ( ) => {
297- expect ( rejectSpy ) . toHaveBeenCalled ( ) ;
298- } ) ;
299-
256+ expect ( rejectSpy ) . toHaveBeenCalled ( ) ;
300257 expect ( updateCustomNonceSpy ) . toHaveBeenCalledWith ( '' ) ;
301258 expect ( setNextNonceSpy ) . toHaveBeenCalledWith ( '' ) ;
302259 } ) ;
303260
304- it ( 'invoke required actions when submit button is clicked' , async ( ) => {
261+ it ( 'invoke required actions when submit button is clicked' , ( ) => {
305262 const { getAllByRole } = render ( ) ;
306263 const submitButton = getAllByRole ( 'button' ) [ 1 ] ;
307264 const resolveSpy = jest
308265 . spyOn ( Actions , 'resolvePendingApproval' )
309266 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31973
310267 // eslint-disable-next-line @typescript-eslint/no-explicit-any
311- . mockImplementation ( ( ) => Promise . resolve ( ) as any ) ;
268+ . mockImplementation ( ( ) => ( { } ) as any ) ;
312269 const updateCustomNonceSpy = jest
313270 . spyOn ( Actions , 'updateCustomNonce' )
314271 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31973
315272 // eslint-disable-next-line @typescript-eslint/no-explicit-any
316- . mockReturnValue ( { } as any ) ;
273+ . mockImplementation ( ( ) => ( { } ) as any ) ;
317274 const setNextNonceSpy = jest
318275 . spyOn ( Actions , 'setNextNonce' )
319276 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31973
320277 // eslint-disable-next-line @typescript-eslint/no-explicit-any
321- . mockReturnValue ( { } as any ) ;
322-
278+ . mockImplementation ( ( ) => ( { } ) as any ) ;
323279 fireEvent . click ( submitButton ) ;
324-
325- // Wait for async onSubmit to complete
326- await waitFor ( ( ) => {
327- expect ( resolveSpy ) . toHaveBeenCalled ( ) ;
328- } ) ;
329-
280+ expect ( resolveSpy ) . toHaveBeenCalled ( ) ;
330281 expect ( updateCustomNonceSpy ) . toHaveBeenCalledWith ( '' ) ;
331282 expect ( setNextNonceSpy ) . toHaveBeenCalledWith ( '' ) ;
332283 } ) ;
@@ -527,7 +478,7 @@ describe('ConfirmFooter', () => {
527478 // @ts -expect-error This is missing from the Mocha type definitions
528479 it . each ( [ 'Confirm' , 'Cancel' ] ) (
529480 'on %s button click' ,
530- async ( buttonText : string ) => {
481+ ( buttonText : string ) => {
531482 const navigateNextMock = jest . fn ( ) ;
532483 useConfirmationNavigationMock . mockReturnValue ( {
533484 navigateNext : navigateNextMock ,
@@ -537,21 +488,17 @@ describe('ConfirmFooter', () => {
537488 const mockStateWithContractInteractionConfirmation =
538489 getMockContractInteractionConfirmState ( ) ;
539490
540- // Get the actual transaction from the transactions array
541- const contractInteractionConfirmation =
542- mockStateWithContractInteractionConfirmation . metamask
543- . transactions [ 0 ] ;
544-
545491 mockStateWithContractInteractionConfirmation . metamask . pendingApprovals =
546492 {
493+ [ addEthereumChainApproval . id ] : addEthereumChainApproval ,
547494 ...mockStateWithContractInteractionConfirmation . metamask
548495 . pendingApprovals ,
549- [ addEthereumChainApproval . id ] : addEthereumChainApproval ,
550496 } ;
551497 mockStateWithContractInteractionConfirmation . metamask . pendingApprovalCount = 2 ;
552498
499+ // Current confirmation is add ethereum chain
553500 jest . spyOn ( confirmContext , 'useConfirmContext' ) . mockReturnValue ( {
554- currentConfirmation : contractInteractionConfirmation ,
501+ currentConfirmation : addEthereumChainApproval ,
555502 isScrollToBottomCompleted : true ,
556503 setIsScrollToBottomCompleted : ( ) => undefined ,
557504 } ) ;
@@ -562,13 +509,10 @@ describe('ConfirmFooter', () => {
562509 const button = getByText ( buttonText ) ;
563510 fireEvent . click ( button ) ;
564511
565- // Wait for async operations to complete
566- await waitFor ( ( ) => {
567- expect ( navigateNextMock ) . toHaveBeenCalledTimes ( 1 ) ;
568- } ) ;
569-
512+ // It will navigate to transaction confirmation
513+ expect ( navigateNextMock ) . toHaveBeenCalledTimes ( 1 ) ;
570514 expect ( navigateNextMock ) . toHaveBeenCalledWith (
571- contractInteractionConfirmation . id ,
515+ addEthereumChainApproval . id ,
572516 ) ;
573517 } ,
574518 ) ;
0 commit comments