React-dates: accessing singleDatePicker through shallow rendering

Created on 13 Jun 2018  路  2Comments  路  Source: airbnb/react-dates

<SingleDatePicker
            date={this.state.createdAt}
            onDateChange={this.onDateChange}
            focused={this.state.calendarFocused}
            onFocusChange={this.onFocusChange}
            numberOfMonths={1}
            isOutsideRange={() => false}/>

this is my component

and I want to access SingleDatePicker in my jest test file like
wrapper.find('singleDatePicker')
its not showning up.

But there are other inputs are also present in the form which are showing up by this line i.e
wrapper.find('input')

Most helpful comment

@bilal68 using a string is a bit less robust than just importing the component in your test because it compares against the display name. If you do

import { SingleDatePicker } from 'react-dates';

it('', () => {
  const wrapper = ...;
  expect(wrapper.find(SingleDatePicker)).to.have.lengthOf(1);
});

that should work.

I think technically the display name of the component is now withStyles(SingleDatePicker).

All 2 comments

@bilal68 using a string is a bit less robust than just importing the component in your test because it compares against the display name. If you do

import { SingleDatePicker } from 'react-dates';

it('', () => {
  const wrapper = ...;
  expect(wrapper.find(SingleDatePicker)).to.have.lengthOf(1);
});

that should work.

I think technically the display name of the component is now withStyles(SingleDatePicker).

Separately, the name is "SingleDatePicker", not "singleDatePicker" - note the capitalization.

Was this page helpful?
0 / 5 - 0 ratings