File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
packages/common/src/test/hooks Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import React , { useEffect } from 'react' ;
2+ import { act } from 'react-dom/test-utils' ;
3+ import { mount } from 'enzyme' ;
4+ import useIsMounted from '../../hooks' ;
5+
6+ describe ( 'useIsMounted' , ( ) => {
7+ it ( 'mounts and unmounts' , async ( ) => {
8+ expect . assertions ( 2 ) ;
9+
10+ let wrapper ;
11+ const isMountedSpy = ( { current } ) => current ;
12+
13+ const Dummy = ( ) => {
14+ const isMounted = useIsMounted ( ) ;
15+
16+ useEffect ( ( ) => {
17+ expect ( isMountedSpy ( isMounted ) ) . toEqual ( true ) ;
18+
19+ return ( ) => {
20+ expect ( isMountedSpy ( isMounted ) ) . toEqual ( false ) ;
21+ } ;
22+ } ) ;
23+
24+ return < span > Dummy</ span > ;
25+ } ;
26+
27+ await act ( async ( ) => {
28+ wrapper = mount ( < Dummy /> ) ;
29+ } ) ;
30+ wrapper . update ( ) ;
31+
32+ await act ( async ( ) => {
33+ wrapper . unmount ( ) ;
34+ } ) ;
35+ wrapper . update ( ) ;
36+ } ) ;
37+ } ) ;
You can’t perform that action at this time.
0 commit comments