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

Ability to assert mixed-checked checkboxes #243

Closed
gnapse opened this issue May 6, 2020 · 7 comments
Closed

Ability to assert mixed-checked checkboxes #243

gnapse opened this issue May 6, 2020 · 7 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed needs discussion We need to discuss this to come up with a good solution

Comments

@gnapse
Copy link
Member

gnapse commented May 6, 2020

Describe the feature you'd like:

See testing-library/eslint-plugin-jest-dom#43

Specifically, the difficulty to asserting that a checkbox-like element is not checked or unchecked, but in a middle third state usually known as "mixed".

Suggested implementation:

It could be a new matcher toBeCheckedMixed, but I'm leaning more towards keeping it under toBeChecked, which could receive an optional argument 'mixed' (specifically that string, and nothing more), and will pass if the checkbox is in this third state. Without argument it will behave as today. When passed another argument, its behavior is undefined (maybe throw an error? or maybe we should support passing to it 'true' and 'false' and fail or pass accordingly, and still fail with anything else passed to it?)

Describe alternatives you've considered:

Keep using toHaveAttribute('aria-checked', 'mixed') but in addition to cause the linting issue linked to above, it does not cover the other way in which a checkbox can be mixed-checked: checkboxElement.indeterminate = true (ref).

Teachability, Documentation, Adoption, Migration Strategy:

Add to the documentation the new feature. It does not / should not break existing functionality.

@gnapse gnapse added help wanted Extra attention is needed good first issue Good for newcomers needs discussion We need to discuss this to come up with a good solution labels May 6, 2020
@gnapse gnapse changed the title toBeChecked('mixed') Ability to assert mixed-checked checkboxes May 6, 2020
@rubenmoya
Copy link
Contributor

Hi! I'd love to take on this one to compensate the fail with the toBeReadonly PR 😂

About the matchers I like the idea of having toBeChecked('mixed') instead of toBeCheckedMixed, but I'm not so sure with true and false as arguments, toBeChecked('true') would be the same as toBeChecked so probably would end up adding more work in the eslint-plugin-jest-dom package to alert the user, and so would happen with toBeChecked('false') and .not.toBeChecked, what do you think?

Also, after reading about the "mixed" state I've found out that:

The switch role does not support the value mixed for the aria-checked attribute; assigning a value of mixed to a switch instead sets the value to false.

So we should take that into account too.

@gnapse
Copy link
Member Author

gnapse commented May 7, 2020

Thanks for your input. Yeah, it does not make much sense to add the argument for the other cases. Which makes me think if it makes sense to add it at all. Maybe we should add toBePartiallyChecked after all. What do you think?

About the mixed state not supported on a switch, yes, we should take that into account.

@rubenmoya
Copy link
Contributor

Yeah, I like toBePartiallyChecked better, it's more concise and it won't complicate toBeChecked with extra arguments and checks, also it will appear in autocompletion with toBe... so probably easier to use than using arguments, I'm sold!

@gnapse
Copy link
Member Author

gnapse commented May 7, 2020

Thanks for your input. Will you take a crack at it with a PR?

@rubenmoya
Copy link
Contributor

Sure! I'll give it a try

@rubenmoya
Copy link
Contributor

We can close this right?

@gnapse
Copy link
Member Author

gnapse commented May 21, 2020

Yup

@gnapse gnapse closed this as completed May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed needs discussion We need to discuss this to come up with a good solution
Projects
None yet
Development

No branches or pull requests

2 participants