Reputation: 263
Trying to run a test and my function is not returning what I expect based on my case. Not sure if I am applying the conditions correctly
here is the function :
renderColumnDropdown = () => {
if (this.props.columnIdList != undefined) {
let columnOptions = Object.keys(this.props.columnIdList).map(key => {
switch (key) {
case 'sort':
return false
case 'filters':
return false
})
return (
default:
return (
<option value={key} key={key}>{this.props.columnIdList[key]}</option>
)
return (
<select value={this.state.column} name='column' id='filter-column' onChange={this.handleChange} defaultValue={this.props.defaultData != null ? this.props.defaultData.column : 'default'}>
{columnOptions}
</select>
)
Here is what I have for my test so far: using jest and enzyme for React JS
it('Test renderColumnDropdown method',() => {
wrapper.setProps({
columnIdList:[],
columnOptions:[{
case:'sort'
}]
})
wrapper.update();
expect(wrapper.instance().renderColumnDropdown({columnOptions:[{case:""}]})).toEqual();
});
I expected to return a message saying that is Equal to false, but right now is returning "
What can adjust on my props to make sure I can test each case scenario
Upvotes: 0
Views: 276
Reputation: 222354
renderColumnDropdown
iterates over columnIdList
prop, not columnOptions
.
It likely should be:
wrapper.setProps({
columnIdList:[{
case:'sort'
}]
})
It also doesn't accept arguments like renderColumnDropdown({columnOptions:[{case:""}]})
The function returns React elements, they can be rendered:
const columnsWrapper = shallow(wrapper.instance().renderColumnDropdown());
Then a wrapper can be asserted that options are expected there or not:
expect(columnsWrapper.find('select').dive().find('option')).to.have.lengthOf(0);
Upvotes: 2