Test for hidden value workarounds for checkbox inputs so they can sen… #609
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
This PR adds a test and special case logic to handle the somewhat common case of checkboxes with hidden inputs. See the why section below for an example. We suspect this situation is not too common in React code since a lot of react code is reading checkboxes and submitting the data through XHR or some other method. But some react code will render a
tag with inside it and submit it through the normal browser mechanism. When one is doing that, checkboxes often need this special hidden field. So this PR allows this case to not raise an error when callingtoHaveFormValues()
Why:
The bug is when I have a form with a checkbox input such as below, it is a common workaround to have a matching hidden input so that if the checkbox is NOT checked, a false false is still sent through the form. However
toHaveFormValues
flags this as an error "Multiple form elements with the same name must be of the same type"How:
We added a test case, and an
if
statement in the code for identifying this situation.Checklist:
Updated Type DefinitionsN/A