@@ -26,6 +26,7 @@ import {
26
26
lazy ,
27
27
PureComponent ,
28
28
Suspense ,
29
+ useCallback ,
29
30
useEffect ,
30
31
useMemo ,
31
32
useLayoutEffect ,
@@ -412,7 +413,7 @@ describe('shallow', () => {
412
413
} ) ;
413
414
414
415
const context = { name : 'foo' } ;
415
- expect ( ( ) => shallow ( < SimpleComponent /> , { context } ) ) . to . not . throw ( ) ;
416
+ expect ( ( ) => shallow ( < SimpleComponent /> , { context } ) ) . not . to . throw ( ) ;
416
417
} ) ;
417
418
418
419
it ( 'is introspectable through context API' , ( ) => {
@@ -1214,7 +1215,7 @@ describe('shallow', () => {
1214
1215
1215
1216
it ( 'get same value when using `useMemo` and rerender with same prop in dependencies' , ( ) => {
1216
1217
function Child ( ) {
1217
- return false ;
1218
+ return null ;
1218
1219
}
1219
1220
function ComponentUsingMemoHook ( props ) {
1220
1221
const { count } = props ;
@@ -1232,7 +1233,7 @@ describe('shallow', () => {
1232
1233
1233
1234
it ( 'get different value when using `useMemo` and rerender with different prop in dependencies' , ( ) => {
1234
1235
function Child ( ) {
1235
- return false ;
1236
+ return null ;
1236
1237
}
1237
1238
function ComponentUsingMemoHook ( props ) {
1238
1239
const { count, relatedProp } = props ;
@@ -1245,7 +1246,45 @@ describe('shallow', () => {
1245
1246
const initialValue = wrapper . find ( Child ) . prop ( 'memoized' ) ;
1246
1247
wrapper . setProps ( { relatedProp : '123' } ) ;
1247
1248
const nextValue = wrapper . find ( Child ) . prop ( 'memoized' ) ;
1248
- expect ( initialValue ) . to . not . equal ( nextValue ) ;
1249
+ expect ( initialValue ) . not . to . equal ( nextValue ) ;
1250
+ } ) ;
1251
+
1252
+ it . skip ( 'get same callback when using `useCallback` and rerender with same prop in dependencies' , ( ) => {
1253
+ function Child ( ) {
1254
+ return false ;
1255
+ }
1256
+ function ComponentUsingCallbackHook ( props ) {
1257
+ const { onChange } = props ;
1258
+ const callback = useCallback ( value => onChange ( value ) , [ onChange ] ) ;
1259
+ return (
1260
+ < Child callback = { callback } />
1261
+ ) ;
1262
+ }
1263
+ const onChange = ( ) => { } ;
1264
+ const wrapper = shallow ( < ComponentUsingCallbackHook onChange = { onChange } /> ) ;
1265
+ const initialCallback = wrapper . find ( Child ) . prop ( 'callback' ) ;
1266
+ wrapper . setProps ( { unRelatedProp : '123' } ) ;
1267
+ const nextCallback = wrapper . find ( Child ) . prop ( 'callback' ) ;
1268
+ expect ( initialCallback ) . to . equal ( nextCallback ) ;
1269
+ } ) ;
1270
+
1271
+ it ( 'get different callback when using `useCallback` and rerender with different prop in dependencies' , ( ) => {
1272
+ function Child ( ) {
1273
+ return false ;
1274
+ }
1275
+ function ComponentUsingCallbackHook ( props ) {
1276
+ const { onChange, relatedProp } = props ;
1277
+ const callback = useCallback ( value => onChange ( value ) , [ onChange , relatedProp ] ) ;
1278
+ return (
1279
+ < Child callback = { callback } />
1280
+ ) ;
1281
+ }
1282
+ const onChange = ( ) => { } ;
1283
+ const wrapper = shallow ( < ComponentUsingCallbackHook onChange = { onChange } relatedProp = "456" /> ) ;
1284
+ const initialCallback = wrapper . find ( Child ) . prop ( 'callback' ) ;
1285
+ wrapper . setProps ( { relatedProp : '123' } ) ;
1286
+ const nextCallback = wrapper . find ( Child ) . prop ( 'callback' ) ;
1287
+ expect ( initialCallback ) . not . to . equal ( nextCallback ) ;
1249
1288
} ) ;
1250
1289
} ) ;
1251
1290
@@ -1399,7 +1438,7 @@ describe('shallow', () => {
1399
1438
1400
1439
const context = { name : 'foo' } ;
1401
1440
const wrapper = shallow ( < Foo /> ) ;
1402
- expect ( ( ) => wrapper . find ( Bar ) . shallow ( { context } ) ) . to . not . throw ( ) ;
1441
+ expect ( ( ) => wrapper . find ( Bar ) . shallow ( { context } ) ) . not . to . throw ( ) ;
1403
1442
} ) ;
1404
1443
1405
1444
it ( 'is introspectable through context API' , ( ) => {
@@ -1501,7 +1540,7 @@ describe('shallow', () => {
1501
1540
1502
1541
const context = { name : 'foo' } ;
1503
1542
const wrapper = shallow ( < Foo /> ) ;
1504
- expect ( ( ) => wrapper . find ( Bar ) . shallow ( { context } ) ) . to . not . throw ( ) ;
1543
+ expect ( ( ) => wrapper . find ( Bar ) . shallow ( { context } ) ) . not . to . throw ( ) ;
1505
1544
} ) ;
1506
1545
1507
1546
itIf ( is ( '< 16' ) , 'is introspectable through context API' , ( ) => {
0 commit comments