8
8
} from '@testing-library/react' ;
9
9
10
10
import toast , { resolveValue , Toaster , ToastIcon } from '../src' ;
11
- import { TOAST_EXPIRE_DISMISS_DELAY , defaultTimeouts } from '../src/core/store' ;
11
+ import { defaultTimeouts } from '../src/core/store' ;
12
+ import { REMOVE_DELAY } from '../src/core/use-toaster' ;
12
13
13
14
beforeEach ( ( ) => {
14
15
// Tests should run in serial for improved isolation
@@ -70,7 +71,7 @@ test('close notification', async () => {
70
71
71
72
fireEvent . click ( await screen . findByRole ( 'button' , { name : / c l o s e / i } ) ) ;
72
73
73
- waitTime ( TOAST_EXPIRE_DISMISS_DELAY ) ;
74
+ waitTime ( REMOVE_DELAY ) ;
74
75
75
76
expect ( screen . queryByText ( / e x a m p l e / i) ) . not . toBeInTheDocument ( ) ;
76
77
} ) ;
@@ -180,7 +181,9 @@ test('error toast with custom duration', async () => {
180
181
181
182
expect ( screen . queryByText ( / e r r o r / i) ) . toBeInTheDocument ( ) ;
182
183
183
- waitTime ( TOAST_DURATION + TOAST_EXPIRE_DISMISS_DELAY ) ;
184
+ waitTime ( TOAST_DURATION ) ;
185
+
186
+ waitTime ( REMOVE_DELAY ) ;
184
187
185
188
expect ( screen . queryByText ( / e r r o r / i) ) . not . toBeInTheDocument ( ) ;
186
189
} ) ;
@@ -211,7 +214,6 @@ test('different toasts types with dismiss', async () => {
211
214
icon : < span > ICON</ span > ,
212
215
} ) ;
213
216
} ) ;
214
-
215
217
let loadingToastId : string ;
216
218
act ( ( ) => {
217
219
loadingToastId = toast . loading ( 'Loading!' ) ;
@@ -223,25 +225,24 @@ test('different toasts types with dismiss', async () => {
223
225
expect ( screen . queryByText ( '✅' ) ) . toBeInTheDocument ( ) ;
224
226
expect ( screen . queryByText ( 'ICON' ) ) . toBeInTheDocument ( ) ;
225
227
226
- const successDismissTime =
227
- defaultTimeouts . success + TOAST_EXPIRE_DISMISS_DELAY ;
228
+ waitTime ( defaultTimeouts . success ) ;
228
229
229
- waitTime ( successDismissTime ) ;
230
+ waitTime ( REMOVE_DELAY ) ;
230
231
231
232
expect ( screen . queryByText ( / s u c c e s s / i) ) . not . toBeInTheDocument ( ) ;
232
233
expect ( screen . queryByText ( / e r r o r / i) ) . toBeInTheDocument ( ) ;
233
234
234
- waitTime (
235
- defaultTimeouts . error + TOAST_EXPIRE_DISMISS_DELAY - successDismissTime
236
- ) ;
235
+ waitTime ( defaultTimeouts . error ) ;
236
+
237
+ waitTime ( REMOVE_DELAY ) ;
237
238
238
239
expect ( screen . queryByText ( / e r r o r / i) ) . not . toBeInTheDocument ( ) ;
239
240
240
241
act ( ( ) => {
241
242
toast . dismiss ( loadingToastId ) ;
242
243
} ) ;
243
244
244
- waitTime ( TOAST_EXPIRE_DISMISS_DELAY ) ;
245
+ waitTime ( REMOVE_DELAY ) ;
245
246
246
247
expect ( screen . queryByText ( / l o a d i n g / i) ) . not . toBeInTheDocument ( ) ;
247
248
} ) ;
@@ -313,7 +314,8 @@ test('pause toast', async () => {
313
314
314
315
fireEvent . mouseLeave ( toastElement ) ;
315
316
316
- waitTime ( 2000 ) ;
317
+ waitTime ( 1000 ) ;
318
+ waitTime ( 1000 ) ;
317
319
318
320
expect ( toastElement ) . not . toBeInTheDocument ( ) ;
319
321
} ) ;
0 commit comments