File tree 2 files changed +10
-6
lines changed
2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 11
11
"build:es" : " tsc -p tsconfig.es.json" ,
12
12
"build:types" : " tsc -p tsconfig.types.json" ,
13
13
"downlevel-dts" : " downlevel-dts dist-types dist-types/ts3.4" ,
14
- "pretest" : " yarn build" ,
15
14
"test" : " jest --coverage"
16
15
},
17
16
"author" : {
Original file line number Diff line number Diff line change @@ -709,21 +709,26 @@ describe("SignatureV4", () => {
709
709
} ) ;
710
710
711
711
describe ( "ambient Date usage" , ( ) => {
712
- const knownDate = new Date ( "1999-12-31T23:59:59.999Z" ) ;
712
+ let dateSpy ;
713
+ const mockDate = new Date ( ) ;
713
714
714
715
beforeEach ( ( ) => {
715
- Date . now = jest . fn ( ) . mockReturnValue ( knownDate ) as any ;
716
+ dateSpy = jest . spyOn ( global , "Date" ) . mockImplementation ( ( ) => mockDate as unknown as string ) ;
717
+ } ) ;
718
+
719
+ afterEach ( ( ) => {
720
+ expect ( dateSpy ) . toHaveBeenCalledTimes ( 1 ) ;
721
+ jest . clearAllMocks ( ) ;
716
722
} ) ;
717
723
718
724
it ( "should use the current date for presigning if no signing date was supplied" , async ( ) => {
719
- const date = new Date ( ) ;
720
725
const { query } = await signer . presign ( minimalRequest ) ;
721
- expect ( ( query as any ) [ AMZ_DATE_QUERY_PARAM ] ) . toBe ( iso8601 ( date ) . replace ( / [ \- : ] / g, "" ) ) ;
726
+ expect ( ( query as any ) [ AMZ_DATE_QUERY_PARAM ] ) . toBe ( iso8601 ( mockDate ) . replace ( / [ \- : ] / g, "" ) ) ;
722
727
} ) ;
723
728
724
729
it ( "should use the current date for signing if no signing date supplied" , async ( ) => {
725
730
const { headers } = await signer . sign ( minimalRequest ) ;
726
- expect ( headers [ AMZ_DATE_HEADER ] ) . toBe ( iso8601 ( new Date ( ) ) . replace ( / [ \- : ] / g, "" ) ) ;
731
+ expect ( headers [ AMZ_DATE_HEADER ] ) . toBe ( iso8601 ( mockDate ) . replace ( / [ \- : ] / g, "" ) ) ;
727
732
} ) ;
728
733
} ) ;
729
734
} ) ;
You can’t perform that action at this time.
0 commit comments