I want to write a test that will check when I change the value of a select element in my react application.
import React, { Component } from 'react';
const TimeList =(props) =>{
return(
<div>
<label>
Time
<br/>
<select name="lessonTime" value={props.defaultTime} onChange={props.handleChange}>
<option value="8:00">8:00</option>
<option value="8:30">8:30</option>
<option value="9:00">9:00</option>
<option value="10:00">10:00</option>
<option value="12:00">12:00</option>
<option value="13:30">13:30</option>
<option value="19:00">19:00</option>
<option value="19:30">19:30</option>
</select>
</label>
</div>
);
};
export default TimeList;
My Test code:
it('should select correct time',() =>{
const mockFunc = jest.fn();
const wrapper = mount(<TimeList value='10:00'
onChange={mockFunc}/>)
console.log(wrapper.props());
wrapper.find('select').simulate('change',{target:{value:'8:00'}});
expect(wrapper.find('select').props().value).toBe('8:00');
});
The error Im getting is:
Expected value to be (using ===):
"8:00"
Received:
undefined
Difference:
Comparing two different types of values. Expected string but received undefined.
It seems I haven't understood how to test the select element.
Any ideas on how to create this kind of test?