File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -87,3 +87,17 @@ test('renders options.wrapper around node', () => {
8787</div>
8888` )
8989} )
90+
91+ test ( 'flushes useEffect cleanup functions sync on unmount()' , ( ) => {
92+ const spy = jest . fn ( )
93+ function Component ( ) {
94+ React . useEffect ( ( ) => spy , [ ] )
95+ return null
96+ }
97+ const { unmount} = render ( < Component /> )
98+ expect ( spy ) . toHaveBeenCalledTimes ( 0 )
99+
100+ unmount ( )
101+
102+ expect ( spy ) . toHaveBeenCalledTimes ( 1 )
103+ } )
Original file line number Diff line number Diff line change @@ -74,7 +74,11 @@ function render(
7474 el . forEach ( e => console . log ( prettyDOM ( e , maxLength , options ) ) )
7575 : // eslint-disable-next-line no-console,
7676 console . log ( prettyDOM ( el , maxLength , options ) ) ,
77- unmount : ( ) => ReactDOM . unmountComponentAtNode ( container ) ,
77+ unmount : ( ) => {
78+ act ( ( ) => {
79+ ReactDOM . unmountComponentAtNode ( container )
80+ } )
81+ } ,
7882 rerender : rerenderUi => {
7983 render ( wrapUiIfNeeded ( rerenderUi ) , { container, baseElement} )
8084 // Intentionally do not return anything to avoid unnecessarily complicating the API.
You can’t perform that action at this time.
0 commit comments