11import React from 'react' ;
2- import { render , fireEvent } from '@testing-library/react-native' ;
2+ import { act , render , fireEvent } from '@testing-library/react-native' ;
33import MultichainAddressRow from './MultichainAddressRow' ;
44import {
55 SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS ,
@@ -24,6 +24,10 @@ jest.mock('../../../../util/networks', () => ({
2424} ) ) ;
2525
2626describe ( 'MultichainAddressRow' , ( ) => {
27+ afterEach ( ( ) => {
28+ jest . useRealTimers ( ) ;
29+ } ) ;
30+
2731 it ( 'renders MultichainAddressRow correctly' , ( ) => {
2832 const { getByTestId } = render (
2933 < MultichainAddressRow { ...SAMPLE_MULTICHAIN_ADDRESS_ROW_PROPS } /> ,
@@ -142,8 +146,9 @@ describe('MultichainAddressRow', () => {
142146
143147 const copyButton = getByTestId ( MULTICHAIN_ADDRESS_ROW_COPY_BUTTON_TEST_ID ) ;
144148
145- // Simulate pressing the copy button
146- fireEvent . press ( copyButton ) ;
149+ await act ( async ( ) => {
150+ fireEvent . press ( copyButton ) ;
151+ } ) ;
147152
148153 // Callback should be called
149154 expect ( mockCallback ) . toHaveBeenCalled ( ) ;
@@ -176,12 +181,14 @@ describe('MultichainAddressRow', () => {
176181 } ) ;
177182
178183 it ( 'shows toast when copy button is pressed and toastRef is provided' , async ( ) => {
184+ jest . useFakeTimers ( ) ;
179185 const mockCallback = jest . fn ( ) ;
180186 const mockShowToast = jest . fn ( ) ;
187+ const mockCloseToast = jest . fn ( ) ;
181188 const mockToastRef = {
182189 current : {
183190 showToast : mockShowToast ,
184- closeToast : jest . fn ( ) ,
191+ closeToast : mockCloseToast ,
185192 } ,
186193 } ;
187194 const copyParams = {
@@ -199,19 +206,30 @@ describe('MultichainAddressRow', () => {
199206
200207 const copyButton = getByTestId ( MULTICHAIN_ADDRESS_ROW_COPY_BUTTON_TEST_ID ) ;
201208
202- // Simulate pressing the copy button
203- fireEvent . press ( copyButton ) ;
204-
205- // Wait for async operations
206- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
209+ await act ( async ( ) => {
210+ fireEvent . press ( copyButton ) ;
211+ } ) ;
207212
208213 // Toast should be called with Plain variant (no icon)
209214 expect ( mockShowToast ) . toHaveBeenCalled ( ) ;
210215 expect ( mockShowToast ) . toHaveBeenCalledWith (
211216 expect . objectContaining ( {
212217 variant : expect . stringContaining ( 'Plain' ) ,
218+ labelOptions : [ { label : 'Address copied' } ] ,
219+ closeButtonOptions : expect . objectContaining ( {
220+ variant : 'Icon' ,
221+ iconName : IconName . Close ,
222+ } ) ,
213223 } ) ,
214224 ) ;
225+
226+ const toastOptions = mockShowToast . mock . calls [ 0 ] [ 0 ] ;
227+ toastOptions . closeButtonOptions . onPress ( ) ;
228+ expect ( mockCloseToast ) . toHaveBeenCalled ( ) ;
229+
230+ act ( ( ) => {
231+ jest . advanceTimersByTime ( 400 ) ;
232+ } ) ;
215233 } ) ;
216234
217235 it ( 'renders truncated address correctly when copyParams is missing' , ( ) => {
0 commit comments