@@ -3,13 +3,20 @@ import * as React from 'react';
33import { Text } from 'react-native' ;
44
55import { act , renderHook } from '..' ;
6+ import { _console } from '../helpers/logger' ;
67import { excludeConsoleMessage } from '../test-utils/console' ;
78
89// eslint-disable-next-line no-console
910const originalConsoleError = console . error ;
11+
12+ beforeEach ( ( ) => {
13+ jest . spyOn ( _console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
14+ } ) ;
15+
1016afterEach ( ( ) => {
1117 // eslint-disable-next-line no-console
1218 console . error = originalConsoleError ;
19+ jest . restoreAllMocks ( ) ;
1320} ) ;
1421
1522function useSuspendingHook ( promise : Promise < string > ) {
@@ -289,3 +296,42 @@ test('handles custom hooks with complex logic', async () => {
289296 } ) ;
290297 expect ( result . current . count ) . toBe ( 4 ) ;
291298} ) ;
299+
300+ test ( 'does not warn when no options are passed' , async ( ) => {
301+ function useTestHook ( ) {
302+ return React . useState ( 0 ) ;
303+ }
304+
305+ await renderHook ( useTestHook ) ;
306+
307+ expect ( _console . warn ) . not . toHaveBeenCalled ( ) ;
308+ } ) ;
309+
310+ test ( 'does not warn when only valid options are passed' , async ( ) => {
311+ const Context = React . createContext ( 'default' ) ;
312+
313+ function useTestHook ( ) {
314+ return React . useContext ( Context ) ;
315+ }
316+
317+ function Wrapper ( { children } : { children : ReactNode } ) {
318+ return < Context . Provider value = "provided" > { children } </ Context . Provider > ;
319+ }
320+
321+ await renderHook ( useTestHook , { wrapper : Wrapper , initialProps : undefined } ) ;
322+
323+ expect ( _console . warn ) . not . toHaveBeenCalled ( ) ;
324+ } ) ;
325+
326+ test ( 'warns when unknown option is passed' , async ( ) => {
327+ function useTestHook ( ) {
328+ return React . useState ( 0 ) ;
329+ }
330+
331+ await renderHook ( useTestHook , { unknownOption : 'value' } as any ) ;
332+
333+ expect ( _console . warn ) . toHaveBeenCalledTimes ( 1 ) ;
334+ expect ( jest . mocked ( _console . warn ) . mock . calls [ 0 ] [ 0 ] ) . toContain (
335+ 'Unknown option(s) passed to renderHook: unknownOption' ,
336+ ) ;
337+ } ) ;
0 commit comments