Skip to content

Commit e72cd02

Browse files
committed
Test for hidden value workarounds for checkbox inputs so they can send "false"
1 parent fd9ee68 commit e72cd02

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/__tests__/to-have-form-values.js

+13
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ describe('.toHaveFormValues', () => {
189189
}).toThrowError(/must be of the same type/)
190190
})
191191

192+
it('allows a checkbox and a hidden input which is a common workaround so forms can send "false" for a checkbox', () => {
193+
const {container} = render(`
194+
<form>
195+
<input type="hidden" name="sample-checkbox" value=0>
196+
<input type="checkbox" name="sample-checkbox" value=1>
197+
</form>
198+
`)
199+
const form = container.querySelector('form')
200+
expect(() => {
201+
expect(form).toHaveFormValues({ "sample-checkbox": 1})
202+
}).not.toThrowError()
203+
})
204+
192205
it('detects multiple elements with the same type and name', () => {
193206
const {container} = render(`
194207
<form>

0 commit comments

Comments
 (0)