File tree 2 files changed +19
-1
lines changed
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', () => {
87
87
</div>
88
88
` )
89
89
} )
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(
74
74
el . forEach ( e => console . log ( prettyDOM ( e , maxLength , options ) ) )
75
75
: // eslint-disable-next-line no-console,
76
76
console . log ( prettyDOM ( el , maxLength , options ) ) ,
77
- unmount : ( ) => ReactDOM . unmountComponentAtNode ( container ) ,
77
+ unmount : ( ) => {
78
+ act ( ( ) => {
79
+ ReactDOM . unmountComponentAtNode ( container )
80
+ } )
81
+ } ,
78
82
rerender : rerenderUi => {
79
83
render ( wrapUiIfNeeded ( rerenderUi ) , { container, baseElement} )
80
84
// Intentionally do not return anything to avoid unnecessarily complicating the API.
You can’t perform that action at this time.
0 commit comments