enzymejs/chai-enzyme

Value assertion does not work on HTML <select> elements

Closed this issue · 7 comments

If I have this element:

<input value={1} />

This assertion is true, as expected:

element.should.have.value(1)

If I have this element:

<select value={1}>
    <option value={1}>1</option>
</select>

The same assertion fails, value is supposedly undefined.

@pahund because select doesn't have values, and its value depends on having a selected <option>. Try adding selected to the option tag, and remove "value" from <select>.

That's what I did at first, but when I do, React gives me a warning message on the console that I should use "value" on my select tag instead of "selected" on an option tag.

Ah, interesting. In that case I think your expectation (that it works) is reasonable.

Not too long ago I've added value support for textarea HTML elements in #63, I had already created an issue #64 to fix this for select HTML elements too.

I will close #64 since this issue has more info. I can work on a solution when I have some spare time.

Thanks @ayrton and @ljharb, keep up the good work!

Fixed in #82