Undefined is not a constructor when unit testing with enzyme mount() #12
Description
We are using the react-input-enhancements combobox on a form we're unit testing with enzyme. We have some child components within the component that we would like to test using a full rendering mount with enzyme, but when mounting it, we get this error from the combobox:
undefined is not a constructor (evaluating '[opt, opt.text, opt.label, opt.value].find(function (value) {
return typeof value === 'string';
})')
I've logged opt
. It and all it's child properties are logging successfully for the first combobox, but for some reason, it seems to fail after this. All subsequent objects in the array are also valid. I can't find what is actually undefined here. Note that this undefined is not a constructor
error only happens when unit testing—not when running the actual front-end.
Here is the combobox element:
<div className='input-group'>
<label htmlFor='create-account-country'>Country<span className='required'>*</span></label>
<Combobox
className='select-container'
defaultValue={form['create-account-country']}
options={this.props.countryOptions}
autocomplete
onValueChange={this.valueChange('create-account-country', 'country')}
data-fieldname='country'
>
<input
type='text'
placeholder='Please select your country'
id='create-account-country'
name='create-account-country'
className={'form-control select' + (!this.isValid('country') ? ' error' : '')}
required
/>
</Combobox>
</div>
Here is the options property that is passed to the combobox:
countryOptions: [
{
value: 'USA',
text: 'United States',
label: 'United States'
},
{
value: 'Canada',
text: 'Canada',
label: 'Canada'
}
]
I're not sure if this issue should be addressed within react-input-enhancements or enyzme but would appreciate any advice you may have in resolving it.