@@ -31,6 +31,7 @@ import {
31
31
forwardRef ,
32
32
memo ,
33
33
PureComponent ,
34
+ useState ,
34
35
} from './_helpers/react-compat' ;
35
36
import {
36
37
describeIf ,
@@ -1534,6 +1535,35 @@ describe('shallow', () => {
1534
1535
} ) ;
1535
1536
} ) ;
1536
1537
1538
+ describeIf ( is ( '>= 16.8' ) , 'hooks' , ( ) => {
1539
+ it ( 'handles useState' , ( ) => {
1540
+ const ComponentUsingStateHook = ( ) => {
1541
+ const [ count ] = useState ( 0 ) ;
1542
+ return < div > { count } </ div > ;
1543
+ } ;
1544
+
1545
+ const wrapper = shallow ( < ComponentUsingStateHook /> ) ;
1546
+
1547
+ expect ( wrapper . find ( 'div' ) . length ) . to . equal ( 1 ) ;
1548
+ expect ( wrapper . find ( 'div' ) . text ( ) ) . to . equal ( '0' ) ;
1549
+ } ) ;
1550
+
1551
+ it ( 'handles setState returned from useState' , ( ) => {
1552
+ const ComponentUsingStateHook = ( ) => {
1553
+ const [ count , setCount ] = useState ( 0 ) ;
1554
+ return < div onClick = { ( ) => setCount ( count + 1 ) } > { count } </ div > ;
1555
+ } ;
1556
+
1557
+ const wrapper = shallow ( < ComponentUsingStateHook /> ) ;
1558
+ const div = wrapper . find ( 'div' ) ;
1559
+ const setCount = div . prop ( 'onClick' ) ;
1560
+ setCount ( ) ;
1561
+ wrapper . update ( ) ;
1562
+
1563
+ expect ( wrapper . find ( 'div' ) . text ( ) ) . to . equal ( '1' ) ;
1564
+ } ) ;
1565
+ } ) ;
1566
+
1537
1567
describeWithDOM ( 'find DOM elements by constructor' , ( ) => {
1538
1568
const { elements, all } = getData ( ) ;
1539
1569
0 commit comments