@gitlab/ui
Version:
GitLab UI Components
30 lines (27 loc) • 602 B
JavaScript
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()],
* })
*/
const useFakeDate = () => {
if (process.env.IS_VISUAL_TEST) {
return {
created() {
MockDate.set('2020-01-10', 0);
},
destroyed() {
MockDate.reset();
}
};
}
return {};
};
export { useFakeDate };