Skip to content

Commit

Permalink
Merge isDisabled and isNotDisabled helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Apr 19, 2018
1 parent 9c2cb8c commit 074ec4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 35 deletions.
3 changes: 1 addition & 2 deletions lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import isNotRequired from './assertions/is-not-required';
import isVisible from './assertions/is-visible';
import isNotVisible from './assertions/is-not-visible';
import isDisabled from './assertions/is-disabled';
import isNotDisabled from './assertions/is-not-disabled';

import elementToString from './helpers/element-to-string';
import collapseWhitespace from './helpers/collapse-whitespace';
Expand Down Expand Up @@ -335,7 +334,7 @@ export default class DOMAssertions {
* @see {@link #isDisabled}
*/
isNotDisabled(message) {
isNotDisabled.call(this, message);
isDisabled.call(this, message, { inverted: true });
}

/**
Expand Down
18 changes: 11 additions & 7 deletions lib/assertions/is-disabled.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export default function isDisabled(message) {
export default function isDisabled(message, options = {}) {
let { inverted } = options;

let element = this.findTargetElement();
if (!element) return;

Expand All @@ -14,13 +16,15 @@ export default function isDisabled(message) {
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;
let result = element.disabled === !inverted;

if (result === false) {
actual = `Element ${this.targetDescription} is not disabled`;
}
let actual = element.disabled === false
? `Element ${this.targetDescription} is not disabled`
: `Element ${this.targetDescription} is disabled`;

let expected = inverted
? `Element ${this.targetDescription} is not disabled`
: `Element ${this.targetDescription} is disabled`;

if (!message) {
message = expected;
Expand Down
26 changes: 0 additions & 26 deletions lib/assertions/is-not-disabled.js

This file was deleted.

0 comments on commit 074ec4a

Please sign in to comment.