@@ -108,9 +108,13 @@ const mockAllMarkets = [
108108 ...mockMarketsWithInvalidVolume ,
109109] ;
110110
111+ const NOW = 1_700_000_000_000 ; // fixed epoch ms for deterministic listedAt math
112+ const DAYS_AGO = ( days : number ) => NOW - days * 24 * 60 * 60 * 1000 ;
113+
111114describe ( 'usePerpsMarketListView' , ( ) => {
112115 beforeEach ( ( ) => {
113116 jest . clearAllMocks ( ) ;
117+ jest . spyOn ( Date , 'now' ) . mockReturnValue ( NOW ) ;
114118
115119 // Reset sortMarkets mock to pass through by default
116120 mockSortMarkets . mockImplementation ( ( { markets } ) => markets ) ;
@@ -158,6 +162,10 @@ describe('usePerpsMarketListView', () => {
158162 mockSelectorState ( { watchlist : [ 'BTC' , 'ETH' ] } ) ;
159163 } ) ;
160164
165+ afterEach ( ( ) => {
166+ jest . restoreAllMocks ( ) ;
167+ } ) ;
168+
161169 describe ( 'Initial State' , ( ) => {
162170 it ( 'returns correct initial state with default parameters' , ( ) => {
163171 const { result } = renderHook ( ( ) => usePerpsMarketListView ( ) ) ;
@@ -664,18 +672,18 @@ describe('usePerpsMarketListView', () => {
664672 {
665673 ...createMockMarket ( 'BTC' , '$1B' ) ,
666674 isHip3 : false ,
667- listedAt : Date . now ( ) - 5 * 24 * 60 * 60 * 1000 , // 5 days ago
675+ listedAt : DAYS_AGO ( 5 ) , // 5 days ago
668676 } ,
669677 {
670678 ...createMockMarket ( 'AAPL' , '$2B' ) ,
671679 marketType : 'stock' as const ,
672680 isHip3 : true ,
673- listedAt : Date . now ( ) - 10 * 24 * 60 * 60 * 1000 , // 10 days ago
681+ listedAt : DAYS_AGO ( 10 ) , // 10 days ago
674682 } ,
675683 {
676684 ...createMockMarket ( 'OLDCOIN' , '$500M' ) ,
677685 isHip3 : false ,
678- listedAt : Date . now ( ) - 45 * 24 * 60 * 60 * 1000 , // 45 days ago, not new
686+ listedAt : DAYS_AGO ( 45 ) , // 45 days ago, not new
679687 } ,
680688 ] ;
681689
@@ -989,19 +997,19 @@ describe('usePerpsMarketListView', () => {
989997 {
990998 ...createMockMarket ( 'SHIB2' , '$100M' ) ,
991999 isHip3 : false ,
992- listedAt : Date . now ( ) - 3 * 24 * 60 * 60 * 1000 , // 3 days ago, new
1000+ listedAt : DAYS_AGO ( 3 ) , // 3 days ago, new
9931001 } ,
9941002 {
9951003 ...createMockMarket ( 'CASHCAT' , '$50M' ) ,
9961004 marketType : 'stock' as const ,
9971005 isHip3 : true ,
998- listedAt : Date . now ( ) - 20 * 24 * 60 * 60 * 1000 , // 20 days ago, new
1006+ listedAt : DAYS_AGO ( 20 ) , // 20 days ago, new
9991007 } ,
10001008 {
10011009 ...createMockMarket ( 'OLDIPO' , '$30M' ) ,
10021010 marketType : 'pre-ipo' as const ,
10031011 isHip3 : true ,
1004- listedAt : Date . now ( ) - 60 * 24 * 60 * 60 * 1000 , // 60 days ago, not new
1012+ listedAt : DAYS_AGO ( 60 ) , // 60 days ago, not new
10051013 } ,
10061014 ] ;
10071015
0 commit comments