Skip to content

Commit

Permalink
mock Date.now so persistance tests don't rely on actual time (needed …
Browse files Browse the repository at this point in the history
…for updatedAt and snapshot testing)
  • Loading branch information
pieh committed Dec 13, 2020
1 parent d179454 commit aa421fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Object {
"path": "/my-sweet-new-page/",
"pluginCreatorId": "",
"pluginCreator___NODE": "",
"updatedAt": 1606471951096,
"updatedAt": 1,
},
},
"pendingPageDataWrites": Object {
Expand Down
8 changes: 8 additions & 0 deletions packages/gatsby/src/redux/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ describe(`redux db`, () => {
const initialComponentsState = _.cloneDeep(store.getState().components)

beforeEach(() => {
// mock Date.now so Date.now() doesn't change in between tests
const RealDateNow = Date.now
let DateNowCallCount = 0
// simulate passage of time by increasing call counter (instead of actual time value)
Date.now = jest.fn(() => ++DateNowCallCount)

store.dispatch(
createPage(
{
Expand All @@ -107,6 +113,8 @@ describe(`redux db`, () => {
)
)

Date.now = RealDateNow

writeToCache.mockClear()
mockWrittenContent.clear()
})
Expand Down

0 comments on commit aa421fe

Please sign in to comment.