File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 55 parseMutationArgs ,
66 matchMutation ,
77 scheduleMicrotask ,
8+ assert ,
89} from '../utils'
910import { QueryClient , QueryCache , setLogger , Logger } from '../..'
1011import { queryKey } from '../../reactjs/tests/utils'
@@ -389,4 +390,24 @@ describe('core/utils', () => {
389390 jest . useRealTimers ( )
390391 } )
391392 } )
393+
394+ describe ( 'assert' , ( ) => {
395+ it ( 'should assert acccording to condition' , ( ) => {
396+ const logger : Logger = {
397+ error : jest . fn ( ) ,
398+ log : jest . fn ( ) ,
399+ warn : jest . fn ( ) ,
400+ }
401+ setLogger ( logger )
402+
403+ assert ( true , '' )
404+ expect ( logger . warn ) . not . toHaveBeenCalled ( )
405+ assert ( false , '' )
406+ expect ( logger . warn ) . toHaveBeenCalledTimes ( 1 )
407+ assert ( false , '' )
408+ expect ( logger . warn ) . toHaveBeenCalledTimes ( 2 )
409+
410+ setLogger ( console )
411+ } )
412+ } )
392413} )
Original file line number Diff line number Diff line change 1+ import { getLogger } from './logger'
12import type { Mutation } from './mutation'
23import type { Query } from './query'
34import type {
@@ -74,6 +75,15 @@ export function noop(): undefined {
7475 return undefined
7576}
7677
78+ /**
79+ * Raise a dev warning message when the condition is not fulfilled
80+ */
81+ export function assert ( condition : boolean , message : string ) : void {
82+ if ( process . env . NODE_ENV !== 'production' && ! condition ) {
83+ getLogger ( ) . warn ( message )
84+ }
85+ }
86+
7787export function functionalUpdate < TInput , TOutput > (
7888 updater : Updater < TInput , TOutput > ,
7989 input : TInput
You can’t perform that action at this time.
0 commit comments