From 9c2cb8c621b5db35f23bdb40f0a8d202d1642339 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 19 Apr 2018 15:48:50 +0200 Subject: [PATCH] isDisabled: Throw errors for unexpected element types --- lib/assertions/is-disabled.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/assertions/is-disabled.js b/lib/assertions/is-disabled.js index a9ff2c45c..b850470ea 100644 --- a/lib/assertions/is-disabled.js +++ b/lib/assertions/is-disabled.js @@ -2,15 +2,24 @@ export default function isDisabled(message) { let element = this.findTargetElement(); if (!element) return; + if (!( + element instanceof HTMLInputElement || + element instanceof HTMLTextAreaElement || + element instanceof HTMLSelectElement || + element instanceof HTMLButtonElement || + element instanceof HTMLOptGroupElement || + element instanceof HTMLOptionElement || + element instanceof HTMLFieldSetElement + )) { + throw new TypeError(`Unexpected Element Type: ${element.toString()}`); + } + let expected = `Element ${this.targetDescription} is disabled`; let actual = `Element ${this.targetDescription} is disabled`; let result = element.disabled; if (result === false) { actual = `Element ${this.targetDescription} is not disabled`; - } else if(result === undefined) { - actual = `Element ${this.targetDescription} does not support disabled`; - result = false; } if (!message) {