-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: element not allowed to be disabled being returned as disabled (#261
- Loading branch information
Showing
2 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,12 @@ function isElementDisabledByParent(element, parent) { | |
) | ||
} | ||
|
||
function canElementBeDisabled(element) { | ||
return FORM_TAGS.includes(getTag(element)) | ||
} | ||
|
||
function isElementDisabled(element) { | ||
return FORM_TAGS.includes(getTag(element)) && element.hasAttribute('disabled') | ||
return canElementBeDisabled(element) && element.hasAttribute('disabled') | ||
} | ||
|
||
function isAncestorDisabled(element) { | ||
|
@@ -49,10 +53,17 @@ function isAncestorDisabled(element) { | |
) | ||
} | ||
|
||
function isElementOrAncestorDisabled(element) { | ||
return ( | ||
canElementBeDisabled(element) && | ||
(isElementDisabled(element) || isAncestorDisabled(element)) | ||
) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
alexmund-bbc
|
||
} | ||
|
||
export function toBeDisabled(element) { | ||
checkHtmlElement(element, toBeDisabled, this) | ||
|
||
const isDisabled = isElementDisabled(element) || isAncestorDisabled(element) | ||
const isDisabled = isElementOrAncestorDisabled(element) | ||
|
||
return { | ||
pass: isDisabled, | ||
|
@@ -71,7 +82,7 @@ export function toBeDisabled(element) { | |
export function toBeEnabled(element) { | ||
checkHtmlElement(element, toBeEnabled, this) | ||
|
||
const isEnabled = !(isElementDisabled(element) || isAncestorDisabled(element)) | ||
const isEnabled = !isElementOrAncestorDisabled(element) | ||
|
||
return { | ||
pass: isEnabled, | ||
|
I think there's a bug here!
I had this DOM:
And this working test:
I upgraded
@testing-library/jest-dom
from 4.2.4 to 5.11.0, and now my test is failing.I think the problem is that, because a cannot be disabled, the
toBeDisabled
matcher is not checking whether any ancestor ( in this case) is disabled.