File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ import {
8
8
} from '@testing-library/react'
9
9
import useLifecycleHelpers from './'
10
10
11
+ const mockCleanupCallback = jest . fn ( )
12
+ beforeEach ( ( ) => {
13
+ jest . clearAllMocks ( )
14
+ } )
11
15
afterEach ( cleanup )
12
16
13
17
const Component = props => {
@@ -36,6 +40,10 @@ const Component = props => {
36
40
[ 'counter' ]
37
41
)
38
42
43
+ useComponentWillUnmount ( ( ) => {
44
+ mockCleanupCallback ( )
45
+ } )
46
+
39
47
return (
40
48
< div id = 'component' >
41
49
< p > { componentState } </ p >
@@ -76,4 +84,15 @@ describe('Test useLifecycleHelpers custom hook', () => {
76
84
77
85
getByText ( / D e p s U p d a t e d / i)
78
86
} )
87
+
88
+ test ( 'The component should be unmounted' , ( ) => {
89
+ const dom = renderComponent ( )
90
+ const getById = queryByAttribute . bind ( null , 'id' )
91
+ const { unmount } = dom
92
+ unmount ( )
93
+
94
+ const component = getById ( dom . container , 'component' )
95
+ expect ( component ) . toBe ( null )
96
+ expect ( mockCleanupCallback . mock . calls . length ) . toBe ( 1 )
97
+ } )
79
98
} )
You can’t perform that action at this time.
0 commit comments