I was able to test some onClick events on this file, but when it comes to the code below I cannot test. The main reason I believe is because there's a class inside of render which I am not able to test it
I tried to test by className, id etc.. but still getting the same error.
Using jest and enzyme - React JS
here is the onClick event I am trying to test:
<div className='report-wrapper'>
<div className='fields-item-wrapper span-two-col'>
<label className='workflow-label' for=''> Contacts </label>
<Select
className={'field-input-select margin-right'}
id=''
value={this.state.Contact}
onChange={(e) => {let val = e ? e.value : null; this.setState({Contact: e, Account: null, accountOptions: []}); this.getAccounts(e)}}
onClick={() => {this.setState({showRequired: false})} }
options={this.state.contactOptions}
isDisabled={loading}
/>
</div>
Using jest and enzyme - I already mount the component
describe(' Edit Data Test', () => {
let wrapper;
beforeEach(() => wrapper = mount(<BrowserRouter><Component {...baseProps} /></BrowserRouter>));
it("should check button click event - Select class", () => {
baseProps.onClick.mockClear();
wrapper.setState({
showRequired: false,
});
wrapper.update()
wrapper.find('#test').simulate("click");
});
'#test'
? Sounds like it is not finding your element.... – epascarello