11import { useLog } from './index'
2+ import * as utils from './utils'
23import { act , renderHook } from '@testing-library/react'
34import { useEffect , useState } from 'react'
45
56describe ( 'useLog' , ( ) => {
67 const OLD_ENV = process . env
8+ jest . spyOn ( utils , 'getCurrentTime' ) . mockReturnValue ( '09:38 PM' )
79 const consoleLog = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => null )
810 const consoleGroup = jest
911 . spyOn ( console , 'group' )
1012 . mockImplementation ( ( ) => null )
13+
1114 const consoleGroupCollapsed = jest
1215 . spyOn ( console , 'groupCollapsed' )
1316 . mockImplementation ( ( ) => null )
@@ -70,14 +73,14 @@ describe('useLog', () => {
7073 * Set Initial Values
7174 */
7275 expect ( consoleGroup ) . toBeCalledWith (
73- ` Mount in %c<TestComponent /> %c@ ${ new Date ( ) . toLocaleTimeString ( ) } ` ,
76+ ' Mount in %c<TestComponent /> %c@ 09:38 PM' ,
7477 'color: DodgerBlue' ,
7578 'color: SlateGray; font-weight: thin;' ,
7679 )
7780 expect ( consoleLog ) . toBeCalledWith ( ' On mount: null' )
7881
7982 expect ( consoleGroup ) . toBeCalledWith (
80- ` Change in %c<TestComponent /> %c@ ${ new Date ( ) . toLocaleTimeString ( ) } ` ,
83+ ' Change in %c<TestComponent /> %c@ 09:38 PM' ,
8184 'color: DodgerBlue' ,
8285 'color: SlateGray; font-weight: thin;' ,
8386 )
@@ -90,7 +93,7 @@ describe('useLog', () => {
9093 'color: green; font-weight: bold;' ,
9194 )
9295 expect ( consoleGroup ) . toBeCalledWith (
93- ` Change in %c<TestComponent /> %c@ ${ new Date ( ) . toLocaleTimeString ( ) } ` ,
96+ ' Change in %c<TestComponent /> %c@ 09:38 PM' ,
9497 'color: DodgerBlue' ,
9598 'color: SlateGray; font-weight: thin;' ,
9699 )
@@ -113,7 +116,7 @@ describe('useLog', () => {
113116 logRerender ( )
114117 } )
115118 expect ( consoleGroup ) . toBeCalledWith (
116- ` Change in %c<TestComponent /> %c@ ${ new Date ( ) . toLocaleTimeString ( ) } ` ,
119+ ' Change in %c<TestComponent /> %c@ 09:38 PM' ,
117120 'color: DodgerBlue' ,
118121 'color: SlateGray; font-weight: thin;' ,
119122 )
@@ -136,7 +139,7 @@ describe('useLog', () => {
136139 logRerender ( )
137140 } )
138141 expect ( consoleGroup ) . toBeCalledWith (
139- ` Change in %c<TestComponent /> %c@ ${ new Date ( ) . toLocaleTimeString ( ) } ` ,
142+ ' Change in %c<TestComponent /> %c@ 09:38 PM' ,
140143 'color: DodgerBlue' ,
141144 'color: SlateGray; font-weight: thin;' ,
142145 )
@@ -158,7 +161,7 @@ describe('useLog', () => {
158161 logUnmount ( )
159162 } )
160163 expect ( consoleGroup ) . toBeCalledWith (
161- ` Unmount in %c<TestComponent /> %c@ ${ new Date ( ) . toLocaleTimeString ( ) } ` ,
164+ ' Unmount in %c<TestComponent /> %c@ 09:38 PM' ,
162165 'color: DodgerBlue' ,
163166 'color: SlateGray; font-weight: thin;' ,
164167 )
@@ -261,7 +264,7 @@ describe('useLog', () => {
261264 expect ( consoleGroupCollapsed ) . toHaveBeenCalled ( )
262265 // first call, first parameter for group name should exist
263266 expect ( consoleGroupCollapsed . mock . calls [ 0 ] [ 0 ] ) . toBe (
264- ` Mount in %c<TestComponent /> %c@ ${ new Date ( ) . toLocaleTimeString ( ) } ` ,
267+ ' Mount in %c<TestComponent /> %c@ 09:38 PM' ,
265268 )
266269 } )
267270
0 commit comments