File tree 2 files changed +25
-7
lines changed
2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -886,6 +886,11 @@ describe('ReactUpdates', () => {
886
886
'Invalid argument passed as callback. Expected a function. Instead ' +
887
887
'received: [object Object]' ,
888
888
) ;
889
+ component = ReactTestUtils . renderIntoDocument ( < A /> ) ;
890
+ expect ( ( ) => component . setState ( { } , { a : 1 , b : 2 } ) ) . toThrowError (
891
+ 'Invalid argument passed as callback. Expected a function. Instead ' +
892
+ 'received: [object Object]' ,
893
+ ) ;
889
894
} ) ;
890
895
891
896
it ( 'throws in forceUpdate if the update callback is not a function' , ( ) => {
@@ -933,6 +938,11 @@ describe('ReactUpdates', () => {
933
938
'Invalid argument passed as callback. Expected a function. Instead ' +
934
939
'received: [object Object]' ,
935
940
) ;
941
+ component = ReactTestUtils . renderIntoDocument ( < A /> ) ;
942
+ expect ( ( ) => component . forceUpdate ( { a : 1 , b : 2 } ) ) . toThrowError (
943
+ 'Invalid argument passed as callback. Expected a function. Instead ' +
944
+ 'received: [object Object]' ,
945
+ ) ;
936
946
} ) ;
937
947
938
948
it ( 'does not update one component twice in a batch (#2410)' , ( ) => {
Original file line number Diff line number Diff line change @@ -44,16 +44,24 @@ let didWarnAboutStateAssignmentForComponent;
44
44
let warnOnInvalidCallback ;
45
45
46
46
if ( __DEV__ ) {
47
+ const didWarnOnInvalidCallback = { } ;
47
48
didWarnAboutStateAssignmentForComponent = { } ;
48
49
49
50
warnOnInvalidCallback = function ( callback : mixed , callerName : string ) {
50
- warning (
51
- callback === null || typeof callback === 'function' ,
52
- '%s(...): Expected the last optional `callback` argument to be a ' +
53
- 'function. Instead received: %s.' ,
54
- callerName ,
55
- callback ,
56
- ) ;
51
+ if ( callback === null || typeof callback === 'function' ) {
52
+ return ;
53
+ }
54
+ const key = `${ callerName } _${ JSON . stringify ( callback ) } ` ;
55
+ if ( ! didWarnOnInvalidCallback [ key ] ) {
56
+ warning (
57
+ false ,
58
+ '%s(...): Expected the last optional `callback` argument to be a ' +
59
+ 'function. Instead received: %s.' ,
60
+ callerName ,
61
+ callback ,
62
+ ) ;
63
+ didWarnOnInvalidCallback [ key ] = true ;
64
+ }
57
65
} ;
58
66
59
67
// This is so gross but it's at least non-critical and can be removed if
You can’t perform that action at this time.
0 commit comments