File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change 1- import React from 'react' ;
1+ import React , { useEffect , useState } from 'react' ;
22import {
33 render ,
44 screen ,
@@ -319,3 +319,25 @@ test('pause toast', async () => {
319319
320320 expect ( toastElement ) . not . toBeInTheDocument ( ) ;
321321} ) ;
322+
323+ test ( '"toast" can be called from useEffect hook' , async ( ) => {
324+ const MyComponent = ( ) => {
325+ const [ success , setSuccess ] = useState ( false ) ;
326+ useEffect ( ( ) => {
327+ toast . success ( 'Success toast' ) ;
328+ setSuccess ( true ) ;
329+ } , [ ] ) ;
330+
331+ return success ? < div > MyComponent finished</ div > : null ;
332+ } ;
333+
334+ render (
335+ < >
336+ < MyComponent />
337+ < Toaster />
338+ </ >
339+ ) ;
340+
341+ await screen . findByText ( / M y C o m p o n e n t f i n i s h e d / i) ;
342+ expect ( screen . queryByText ( / S u c c e s s t o a s t / i) ) . toBeInTheDocument ( ) ;
343+ } ) ;
You can’t perform that action at this time.
0 commit comments