File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ import { useEffect, useState } from 'react'
44
55describe ( 'useLog' , ( ) => {
66 const OLD_ENV = process . env
7- const consoleLog = jest . spyOn ( console , 'log' )
8- const consoleGroup = jest . spyOn ( console , 'group' )
7+ const consoleLog = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => null )
8+ const consoleGroup = jest
9+ . spyOn ( console , 'group' )
10+ . mockImplementation ( ( ) => null )
911
1012 beforeEach ( ( ) => {
1113 jest . useFakeTimers ( )
@@ -194,4 +196,15 @@ describe('useLog', () => {
194196
195197 expect ( consoleGroup . mock . calls [ 1 ] [ 1 ] ) . toBe ( 'color: darkRed;' )
196198 } )
199+
200+ it ( 'renders anything in custom allowed environments' , ( ) => {
201+ process . env . NODE_ENV = 'test_env'
202+
203+ renderHook ( ( ) => {
204+ const { log } = useLog ( { environments : [ 'test_env' ] } )
205+ log ( 'Test' )
206+ } )
207+
208+ expect ( consoleLog ) . toBeCalled ( )
209+ } )
197210} )
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ export interface UseLog {
1212 changeCSS ?: string
1313 subValueCSS ?: string
1414 }
15+ environments ?: string [ ]
1516}
1617
1718export type Log = UseLog
@@ -40,6 +41,7 @@ export function useLog({
4041 changeCSS = CSS_CHANGE ,
4142 subValueCSS = CSS_SUB_VALUE ,
4243 } = { } ,
44+ environments = ALLOWED_NODE_ENVS ,
4345} : UseLog = { } ) : UseLogReturn {
4446 const componentName =
4547 ( function getComponentName ( ) {
@@ -97,7 +99,7 @@ export function useLog({
9799 console . groupEnd ( )
98100 }
99101
100- if ( ALLOWED_NODE_ENVS . includes ( process . env . NODE_ENV ?? '' ) ) {
102+ if ( environments . includes ( process . env . NODE_ENV ?? '' ) ) {
101103 return ( function logHooks ( ) {
102104 const isUnmounting = useRef ( false )
103105 useEffect ( function setIsUnmounting ( ) {
You can’t perform that action at this time.
0 commit comments