1
1
import { assert } from 'chai' ;
2
+ import Sinon from 'sinon' ;
3
+
2
4
import { TimedLog } from '../../../../util/loggerTimed' ;
3
5
4
6
const second = 's' ;
@@ -20,6 +22,16 @@ function testPairFuzzy({ offset, output }: TimePair) {
20
22
}
21
23
22
24
describe ( 'TimedLog' , ( ) => {
25
+ const mockNow = 1000000 ; // arbitrary timestamp
26
+
27
+ beforeEach ( ( ) => {
28
+ Sinon . stub ( Date , 'now' ) . returns ( mockNow ) ;
29
+ } ) ;
30
+
31
+ afterEach ( ( ) => {
32
+ Sinon . restore ( ) ;
33
+ } ) ;
34
+
23
35
describe ( 'formatDistanceToNow' , ( ) => {
24
36
it ( 'should return exact milliseconds when the time difference is less than 1 second' , ( ) => {
25
37
(
@@ -82,11 +94,11 @@ describe('TimedLog', () => {
82
94
// Millisecond values should be whole numbers but we should still handle non-regular values as its theoretically possible for the time to be a float
83
95
(
84
96
[
85
- { offset : 1.11112123213 , output : `2 ${ ms } ` } ,
97
+ { offset : 1.11112123213 , output : `1 ${ ms } ` } ,
86
98
{ offset : 1.567 , output : `2${ ms } ` } ,
87
99
{ offset : 1.867 , output : `2${ ms } ` } ,
88
100
{ offset : 1001.567 , output : `1.002${ second } ` } ,
89
- { offset : 2002.1 , output : `2.003 ${ second } ` } ,
101
+ { offset : 2002.1 , output : `2.002 ${ second } ` } ,
90
102
{ offset : 10000.0000001 , output : `10${ second } ` } ,
91
103
] satisfies TimePairs
92
104
) . forEach ( testPair ) ;
0 commit comments