File tree Expand file tree Collapse file tree 2 files changed +11
-1
lines changed
packages/gatsby/src/redux/__tests__ Expand file tree Collapse file tree 2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ Object {
6464 " path" : " /my-sweet-new-page/" ,
6565 " pluginCreatorId" : " " ,
6666 " pluginCreator___NODE" : " " ,
67- " updatedAt" : 1606471951096 ,
67+ " updatedAt" : 1 ,
6868 },
6969 } ,
7070 "pendingPageDataWrites": Object {
Original file line number Diff line number Diff line change @@ -91,6 +91,12 @@ describe(`redux db`, () => {
9191 const initialComponentsState = _ . cloneDeep ( store . getState ( ) . components )
9292
9393 beforeEach ( ( ) => {
94+ // mock Date.now so Date.now() doesn't change in between tests
95+ const RealDateNow = Date . now
96+ let DateNowCallCount = 0
97+ // simulate passage of time by increasing call counter (instead of actual time value)
98+ Date . now = jest . fn ( ( ) => ++ DateNowCallCount )
99+
94100 store . dispatch (
95101 createPage (
96102 {
@@ -107,6 +113,8 @@ describe(`redux db`, () => {
107113 )
108114 )
109115
116+ Date . now = RealDateNow
117+
110118 writeToCache . mockClear ( )
111119 mockWrittenContent . clear ( )
112120 } )
@@ -133,6 +141,8 @@ describe(`redux db`, () => {
133141 // make sure data was read and is not the same as our clean redux state
134142 expect ( data . components ) . not . toEqual ( initialComponentsState )
135143
144+ // we ignore pages in this assertion, because it contains `updatedAt` timestamp field that
145+ // will change depending on time tests were executed
136146 expect ( data ) . toMatchSnapshot ( )
137147 } )
138148
You can’t perform that action at this time.
0 commit comments