Skip to content

Commit

Permalink
isDisabled: Throw errors for unexpected element types
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Apr 19, 2018
1 parent 615fd23 commit 9c2cb8c
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/assertions/is-disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9c2cb8c

Please sign in to comment.