-
Notifications
You must be signed in to change notification settings - Fork 401
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
add toBeReadonly matcher #204
Conversation
Codecov Report
@@ Coverage Diff @@
## master #204 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 19 20 +1
Lines 240 252 +12
Branches 58 61 +3
=========================================
+ Hits 240 252 +12
Continue to review full report at Codecov.
|
Hi, @bastibuck. The |
@bastibuck thanks for the contribution.
Because no one has suggested it before, or needed it. You seem to be the first, at least the first to want it enough to bother. Thanks!
I'd say that the "readonly" case is less compelling than the "disabled" case. In the "disabled" case, in addition to the attribute presence, an element could be disabled because it was contained inside a Can you make a case for why |
Hey, thanks for the quick responses and addressing my questions. I totally get the point of what you're saying with the wider use-case of @gnapse Initially I couldn't make up a case other than that I wanted to check if a given field has the readonly attribute set. I s awit more like a nicer way of writing the tests for these cases though. Looking at the code for PS: This brings up the question and maybe another PR: Shouldn't |
This was already brought up, and although it seemed logical at first, it's not that simple. See the discussion in the proposal #144 and the attempted-but-never-merged pull request #146. TL;DR:
Not sure what you're saying here? Are you acknowledging that you can get by with simply checking for the presence of the |
Sorry, my bad. I was trying to say that after looking at the other two matchers I found out that something like aria-readonly exists which my code doesn't check for yet. https://www.w3.org/TR/html-aria/#att-readonly makes it look like If I understand correctly only all other elements can have the aria-readonly attribute set which by itself doesn't result in a change of behaviour for the user. Therefor I'm not sure if it makes sense to check for
This seems just as true for aria-readonly. Which brings us back to the initial question if a matcher like the proposed makes sense at all ;-) IMO it can make for a nicer way of writing tests but this might lead to an unnecessary increase of matchers as there are way more matchers that could be handled with a |
Indeed. I'm leaning towards this being a very small syntactic sugar on top of Thanks for understanding. I'm sorry you devoted time to this. That's why I always encourage people to propose new matchers first in an issue, instead of jumping into the PR. Hopefully this is not the last time we'll see you around contributing. |
Agreed! Don't worry, will contribute if I find or need something. But I will start a discussion before creating a PR the next time 😉 No wasted time though as I learned something. |
What:
This adds two new matchers
toBeReadonly
andtoBeWritable
Why:
While adding tests to a component lately I was expecting jest-dom to have a matcher similar to
toBeDisabled
for readonly form fields. Unfortunately there was none.How:
I added two new matchers
toBeReadonly
andtoBeWritable
based on the very similartoBeDisabled
andtoBeEnabled
matchers. Copy-paste pretty much 😉Checklist:
I was wondering why there was nothing like this before.
Has no one thought about this yet? Is it easy enough to check with
toHaveAttribute
? If so, why is there something liketoBeDisabled
which could just be as simply checked?Also the Type Definitions are not maintained within this repo (anymore), are they? Will submit a PR to DefinatelyTyped after this is merged.