Skip to content
This repository was archived by the owner on Oct 27, 2022. It is now read-only.
This repository was archived by the owner on Oct 27, 2022. It is now read-only.

Undefined is not a constructor when unit testing with enzyme mount() #12

Closed
@binomialstew

Description

@binomialstew

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions