Skip to content

Commit

Permalink
fix: console.errors coming from using Datepicker (carbon-design-syste…
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydiaz authored and alisonjoseph committed May 18, 2018
1 parent c461fd7 commit 984434e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/components/DatePicker/DatePicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,40 @@ describe('DatePicker', () => {
expect(datepicker.props().locale).toBe('en');
});
});

describe('Date picker with minDate and maxDate', () => {
console.error = jest.genMockFn(); // eslint-disable-line no-console

const wrapper = mount(
<DatePicker
onChange={() => {}}
datePickerType="range"
className="extra-class"
minDate="01/01/2018"
maxDate="01/30/2018">
<div className="test-child">
<input
type="text"
className="bx--date-picker__input"
id="input-from"
/>
</div>
<div className="test-child">
<input type="text" className="bx--date-picker__input" id="input-to" />
</div>
</DatePicker>
);

it('has the range date picker with min and max dates', () => {
const datepicker = wrapper.find('DatePicker');
expect(datepicker.props().minDate).toBe('01/01/2018');
expect(datepicker.props().maxDate).toBe('01/30/2018');
});

it('should not have "console.error" being created', () => {
expect(console.error).not.toBeCalled(); // eslint-disable-line no-console
});
});
});

describe('DatePickerSkeleton', () => {
Expand Down
12 changes: 12 additions & 0 deletions src/components/DatePicker/DatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ export default class DatePicker extends Component {
* The `change` event handler.
*/
onChange: PropTypes.func,

/**
* The minimum date that a user can start picking from.
*/
minDate: PropTypes.string,

/**
* The maximum date that a user can pick to.
*/
maxDate: PropTypes.string,
};

static defaultProps = {
Expand Down Expand Up @@ -367,6 +377,8 @@ export default class DatePicker extends Component {
className,
short,
datePickerType,
minDate, // eslint-disable-line
maxDate, // eslint-disable-line
dateFormat, // eslint-disable-line
onChange, // eslint-disable-line
...other
Expand Down

0 comments on commit 984434e

Please sign in to comment.