Closed StefanoSega closed 6 years ago
.html()
isn't shallow - it uses cheerio to perform a full render, all the way down.
You might want wrapper.debug()
?
Yes!
with wrapper.debug()
I can see how it's structured:
nsole.log tests/react/components/materialDesign/datetimePicker.test.jsx:28
<ReactPlaceholder type="text" rows={1} ready={true} showLoadingAnimation={true} className="datetime-picker-placeholder" delay={0} color="#CD
CDCD">
<MuiThemeProvider theme={{...}}>
<MuiPickersUtilsProvider utils={[Function: DateFnsUtils]} locale={[undefined]} moment={[undefined]}>
<div className="datetime-picker" data-md-field={true}>
<WithStyles(WithUtils(DateTimePickerWrapper)) value={{...}} onChange={[Function: mockConstructor]} emptyLabel={{...}} clearable={fal
se} shouldDisableDate={[Function: bound shouldDisableDate]} format="DD/MM/YYYY hh:mm A" InputProps={{...}} />
<label htmlFor="test" className="datetime-picker-label">
Date
</label>
</div>
</MuiPickersUtilsProvider>
</MuiThemeProvider>
<input type="hidden" id="test" name="test" value="" />
</ReactPlaceholder>
... so the DateTimePicker component is in the end rendered as a WithStyles component.
Thanks, there's no issue so.
Describe the bug When shallow rendering a component that uses the 3rd party components
react-placeholder
andmaterial-ui-pickers/DateTimePicker
the DateTimePicker is fully rendered in its whole final html.To Reproduce Steps to reproduce the behavior:
export default class DatetimePicker extends PureComponent { static propTypes = { id: PropTypes.string.isRequired, name: PropTypes.string, title: PropTypes.string.isRequired, placeholder: PropTypes.string, value: PropTypes.oneOfType([ PropTypes.instanceOf(Date), PropTypes.string, ]), onChange: PropTypes.func.isRequired, ready: PropTypes.bool, required: PropTypes.bool, // eslint-disable-next-line react/no-unused-prop-types forceValidationError: PropTypes.string, shouldDisableDate: PropTypes.func, }
static defaultProps = { name: null, placeholder: null, value: '', ready: true, required: false, forceValidationError: null, shouldDisableDate: null, }
constructor(props) { super(props);
}
componentDidUpdate() { if (this.props.forceValidationError) { // eslint-disable-next-line no-console console.error(
DateTime field ${this.props.id} error: ${this.props.forceValidationError}
); } }shouldDisableDate(date) { if (this.props.shouldDisableDate) { return this.props.shouldDisableDate(date); }
}
bindActions() { this.shouldDisableDate = this.shouldDisableDate.bind(this); }
render() { const hasValue = !!this.props.value; const name = this.props.name || this.props.id;
} }
import React from 'react'; import { shallow, mount } from 'enzyme'; import DatetimePicker from '../../../../react/components/materialDesign/datetimePicker';
let wrapper; const onChange = jest.fn(); const idPar = 'test';
describe('DatetimePicker', () => { describe('When the field is required and no value is specified', () => { beforeAll(() => { // global.Date = jest.fn(() => mockedDate); wrapper = shallow(<DatetimePicker id={idPar} title="Date" onChange={onChange} required />); });
}); });