Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: Unable to update value in jest/enzyme tests #87

Open
CWSites opened this issue Dec 22, 2018 · 0 comments
Open

Testing: Unable to update value in jest/enzyme tests #87

CWSites opened this issue Dec 22, 2018 · 0 comments

Comments

@CWSites
Copy link

CWSites commented Dec 22, 2018

I'm trying to update the value of a Select2 component, then trigger the onChange to get my test as close to how a real user would.

Component

filterColumns = [
    { text: 'Test', id: 0, value: 'test' },
    { text: 'Foo Bar', id: 1, value: 'foo-bar' }
];

handleInputChange(event) {
     console.log(`${event.currentTarget.name} changed to ${event.currentTarget.value}`);
});
<Select2 jest="filter"
                onChange={this.handleInputChange}
                value={filterArray[i].filter}
                data={this.props.filterColumns} />

Test

Value is never updated, onChange is never called. This is how React + Enzyme say to fire the change event for a select element but it isn't working.

it('addFilter works', () => {
    const wrapper = mount(<CustomFilters filterColumns={filterColumns} />);
    wrapper.find('Select2[jest="filter"]').simulate('change', { target: { value: 'test' } }); 
});

I have also tried the following different ways of updating the value.
filterSelect.value = 'test';
filterSelect.instance().value = 'test';
filterSelect.simulate('change');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant