Browse Source

Fix date mocking

new Date returns a UTC time in node

Close #9743
pull/9753/head
Wei Zhu 7 years ago
parent
commit
edbbaac5f9
  1. 2
      components/date-picker/__tests__/DatePicker.test.js
  2. 3
      tests/shared/demoTest.js

2
components/date-picker/__tests__/DatePicker.test.js

@ -17,7 +17,7 @@ describe('DatePicker', () => {
focusTest(DatePicker);
beforeEach(() => {
MockDate.set(new Date('2016-11-22'));
MockDate.set(moment('2016-11-22'));
});
afterEach(() => {

3
tests/shared/demoTest.js

@ -1,6 +1,7 @@
import glob from 'glob';
import { render } from 'enzyme';
import MockDate from 'mockdate';
import moment from 'moment';
export default function demoTest(component, options = {}) {
const files = glob.sync(`./components/${component}/demo/*.md`);
@ -11,7 +12,7 @@ export default function demoTest(component, options = {}) {
testMethod = test.skip;
}
testMethod(`renders ${file} correctly`, () => {
MockDate.set(new Date('2016-11-22').getTime() + (new Date().getTimezoneOffset() * 60 * 1000));
MockDate.set(moment('2016-11-22'));
const demo = require(`../.${file}`).default; // eslint-disable-line global-require, import/no-dynamic-require
const wrapper = render(demo);
expect(wrapper).toMatchSnapshot();

Loading…
Cancel
Save