Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [DatePicker] Construct new moment objects with custom dateFormat #1074

Merged
merged 2 commits into from
Jun 3, 2020

Conversation

skvale
Copy link
Contributor

@skvale skvale commented Jun 3, 2020

Description

Without these changes this test

test('provide ISO-8601 format date with custom dateFormat in props', () => {
  wrapper = mount(<DatePicker dateFormat='DD-MM-YYYY' defaultValue='01-06-2020' />);
  expect(wrapper.state('isoFormattedDate')).toEqual('2020-06-01');
});

would fail with

Expected: "2020-06-01"
Received: "2020-01-06"

where the isoFormattedDate was created with switched month and day values

And this test

        test('should format isoFormattedDate when a custom dateFormat is passed in props', () => {
            const blur = jest.fn();
            const element = mount(<DatePicker
                dateFormat='DD-MM-YYYY'
                defaultValue='01-06-2020'
                onBlur={blur} />).find('input[type="text"]');
            element.find('input[type="text"]').simulate('click');
            element.find('input[type="text"]').simulate('change', { target: { value: '30-06-2020' } });
            element.find('input[type="text"]').simulate('blur');

            expect(blur).toHaveBeenCalledTimes(1);
            expect(blur).toHaveBeenCalledWith(expect.objectContaining({
                isoFormattedDate: '2020-06-30'
            }));
        });

would fail with

Expected: ObjectContaining {"isoFormattedDate": "2020-06-30"}
Received: {"date": "2020-06-30T05:00:00.000Z", "formattedDate": "30-06-2020", "isoFormattedDate": "Invalid date"}

where it would just fail to create the isoFormattedDate

@skvale skvale self-assigned this Jun 3, 2020
@netlify
Copy link

netlify bot commented Jun 3, 2020

Deploy preview for fundamental-react ready!

Built with commit cd626b6

https://deploy-preview-1074--fundamental-react.netlify.app

Copy link
Contributor

@jbadan jbadan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@skvale skvale merged commit 6d919c2 into master Jun 3, 2020
@skvale skvale deleted the fix/datepicker-custom-date-formats branch June 3, 2020 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants