File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -282,6 +282,20 @@ test('unmount', () => {
282
282
expect ( fn ) . toHaveBeenCalled ( ) ;
283
283
} ) ;
284
284
285
+ test ( 'unmount should handle cleanup functions' , ( ) => {
286
+ const cleanup = jest . fn ( ) ;
287
+ const Component = ( ) => {
288
+ React . useEffect ( ( ) => cleanup ) ;
289
+ return null ;
290
+ } ;
291
+
292
+ const { unmount } = render ( < Component /> ) ;
293
+
294
+ unmount ( ) ;
295
+
296
+ expect ( cleanup ) . toHaveBeenCalledTimes ( 1 ) ;
297
+ } ) ;
298
+
285
299
test ( 'toJSON' , ( ) => {
286
300
const { toJSON } = render ( < MyButton > press me</ MyButton > ) ;
287
301
Original file line number Diff line number Diff line change @@ -46,18 +46,23 @@ export default function render<T>(
46
46
) ;
47
47
const update = updateWithAct ( renderer , wrap ) ;
48
48
const instance = renderer . root ;
49
+ const unmount = ( ) => {
50
+ act ( ( ) => {
51
+ renderer . unmount ( ) ;
52
+ } ) ;
53
+ } ;
49
54
50
- addToCleanupQueue ( renderer . unmount ) ;
55
+ addToCleanupQueue ( unmount ) ;
51
56
52
57
return {
53
58
...getByAPI ( instance ) ,
54
59
...queryByAPI ( instance ) ,
55
60
...findByAPI ( instance ) ,
56
61
...a11yAPI ( instance ) ,
57
62
update,
63
+ unmount,
58
64
container : instance ,
59
65
rerender : update , // alias for `update`
60
- unmount : renderer . unmount ,
61
66
toJSON : renderer . toJSON ,
62
67
debug : debug ( instance , renderer ) ,
63
68
} ;
You can’t perform that action at this time.
0 commit comments