File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -886,6 +886,11 @@ describe('ReactUpdates', () => {
886886 'Invalid argument passed as callback. Expected a function. Instead ' +
887887 'received: [object Object]' ,
888888 ) ;
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+ ) ;
889894 } ) ;
890895
891896 it ( 'throws in forceUpdate if the update callback is not a function' , ( ) => {
@@ -933,6 +938,11 @@ describe('ReactUpdates', () => {
933938 'Invalid argument passed as callback. Expected a function. Instead ' +
934939 'received: [object Object]' ,
935940 ) ;
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+ ) ;
936946 } ) ;
937947
938948 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;
4444let warnOnInvalidCallback ;
4545
4646if ( __DEV__ ) {
47+ const didWarnOnInvalidCallback = { } ;
4748 didWarnAboutStateAssignmentForComponent = { } ;
4849
4950 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+ }
5765 } ;
5866
5967 // 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