diff --git a/src/__tests__/to-be-disabled.js b/src/__tests__/to-be-disabled.js
index 74e13e6f..db0cde56 100644
--- a/src/__tests__/to-be-disabled.js
+++ b/src/__tests__/to-be-disabled.js
@@ -25,6 +25,7 @@ test('.toBeDisabled', () => {
+ x
x
@@ -50,7 +51,11 @@ test('.toBeDisabled', () => {
expect(queryByTestId('deep-option-element')).toBeDisabled()
expect(queryByTestId('a-element')).not.toBeDisabled()
+ expect(queryByTestId('deep-a-element')).not.toBeDisabled()
expect(() => expect(queryByTestId('a-element')).toBeDisabled()).toThrowError()
+ expect(() =>
+ expect(queryByTestId('deep-a-element')).toBeDisabled(),
+ ).toThrowError()
})
test('.toBeDisabled fieldset>legend', () => {
@@ -129,6 +134,7 @@ test('.toBeEnabled', () => {
+ x
x
@@ -173,6 +179,10 @@ test('.toBeEnabled', () => {
expect(() =>
expect(queryByTestId('a-element')).not.toBeEnabled(),
).toThrowError()
+ expect(queryByTestId('deep-a-element')).toBeEnabled()
+ expect(() =>
+ expect(queryByTestId('deep-a-element')).not.toBeEnabled(),
+ ).toThrowError()
})
test('.toBeEnabled fieldset>legend', () => {
diff --git a/src/to-be-disabled.js b/src/to-be-disabled.js
index 9ba177b5..46c3755f 100644
--- a/src/to-be-disabled.js
+++ b/src/to-be-disabled.js
@@ -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))
+ )
+}
+
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,