UNPKG

@gitlab/ui

Version:
28 lines (26 loc) 585 B
import MockDate from 'mockdate'; /** * When applied to a story, this mixin mocks the current date to make * visual tests that rely on the date deterministic * * Usage: * * import { useFakeDate } from '../../../../tests/utils/use_fake_date'; * documentedStoriesOf('some|story') * .add('default', () => ({ * mixins: [useFakeDate()], * }) */ export const useFakeDate = () => { if (process.env.IS_VISUAL_TEST) { return { created() { MockDate.set('2020-01-10', 0); }, destroyed() { MockDate.reset(); }, }; } return {}; };