Jest-dom: Extend toBeValid to support the <form/> element

Created on 17 Aug 2019  路  4Comments  路  Source: testing-library/jest-dom

Describe the feature you'd like:

toBeValid and toBeInvalid could support checks against a <form/> element. <form /> also responds to checkValidity().

Suggested implementation:

Add 'form' to this list:
https://github.com/testing-library/jest-dom/blob/09f7f041805b2a4bcf5ac5c1e8201ee10a69ab9b/src/to-be-invalid.js#L4

Describe alternatives you've considered:

expect(form.checkValidity()).toBe(false)
expect(form.checkValidity()).toBe(true)

Teachability, Documentation, Adoption, Migration Strategy:

The current output does not need to be changed:

expect(element).toBeValid()

Received element is not currently valid:
      <form />

The current documentation does not need to be changed:

| This allows you to check if the value of a form element is currently valid.

| An element is valid if it is not having an aria-invalid attribute or having false as a value and returning true when calling checkValidity().

The documentation could be amended to include an example that checks a <form/>.

enhancement good first issue help wanted

Most helpful comment

Thanks @gnapse, I can work on it next week if that's alright. Should be quick.

All 4 comments

@jsphstls you're right. Are you up to make a PR? I may take this if you prefer. Let me know.

Thanks @gnapse, I can work on it next week if that's alright. Should be quick.

Opened a pull request ^

@gnapse @jsphstls I believe this issue can be closed

Was this page helpful?
0 / 5 - 0 ratings