File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change 1111 "build:es" : " tsc -p tsconfig.es.json" ,
1212 "build:types" : " tsc -p tsconfig.types.json" ,
1313 "downlevel-dts" : " downlevel-dts dist-types dist-types/ts3.4" ,
14- "pretest" : " yarn build" ,
1514 "test" : " jest --coverage"
1615 },
1716 "author" : {
Original file line number Diff line number Diff line change @@ -709,21 +709,26 @@ describe("SignatureV4", () => {
709709 } ) ;
710710
711711 describe ( "ambient Date usage" , ( ) => {
712- const knownDate = new Date ( "1999-12-31T23:59:59.999Z" ) ;
712+ let dateSpy ;
713+ const mockDate = new Date ( ) ;
713714
714715 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 ( ) ;
716722 } ) ;
717723
718724 it ( "should use the current date for presigning if no signing date was supplied" , async ( ) => {
719- const date = new Date ( ) ;
720725 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, "" ) ) ;
722727 } ) ;
723728
724729 it ( "should use the current date for signing if no signing date supplied" , async ( ) => {
725730 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, "" ) ) ;
727732 } ) ;
728733 } ) ;
729734} ) ;
You can’t perform that action at this time.
0 commit comments