Skip to content

Commit

Permalink
add mockdate for consistent snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed May 6, 2024
1 parent e46f83f commit d6e8005
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import '../app/style.css'
import type { Preview } from '@storybook/react'
import { resetMockDB } from '#lib/db.mock'
import type { Preview } from '@storybook/react'
import { onMockCall } from '@storybook/test'
import MockDate from 'mockdate'

onMockCall((spy, args) => {
console.log(spy.name, args)
Expand All @@ -18,6 +19,7 @@ const preview: Preview = {
nextjs: { appDirectory: true },
},
beforeEach() {
MockDate.set('2024-05-04T14:00:00.000Z')
resetMockDB()
},
}
Expand Down
39 changes: 21 additions & 18 deletions mocks/notes.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { type Note } from '@prisma/client'

export const createNotes: () => Note[] = () => [
{
id: '1',
title: 'Module mocking in Storybook?',
body: "Yup, that's a thing now! 🎉",
createdBy: 'storybookjs',
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: '2',
title: 'Hello World',
body: 'RSC is pretty cool, even cooler that Storybook supports it!',
createdBy: 'storybookjs',
createdAt: new Date(),
updatedAt: new Date(),
},
]
export const createNotes: () => Note[] = () => {
const mockedDate = new Date('2024-05-04T14:00:00.000Z')
return [
{
id: '1',
title: 'Module mocking in Storybook?',
body: "Yup, that's a thing now! 🎉",
createdBy: 'storybookjs',
createdAt: mockedDate,
updatedAt: mockedDate,
},
{
id: '2',
title: 'Hello World',
body: 'RSC is pretty cool, even cooler that Storybook supports it!',
createdBy: 'storybookjs',
createdAt: mockedDate,
updatedAt: mockedDate,
},
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"eslint-config-next": "14.2.0",
"eslint-plugin-storybook": "^0.8.0",
"http-server": "^14.1.1",
"mockdate": "^3.0.5",
"playwright": "^1.43.0",
"prettier": "^3.2.5",
"prisma": "^5.11.0",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d6e8005

Please sign in to comment.