expect-webdriverio 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +29 -9
  2. package/jasmine.d.ts +0 -1
  3. package/jest.d.ts +1 -1
  4. package/lib/constants.js +4 -0
  5. package/lib/index.js +14 -6
  6. package/lib/jasmineUtils.js +7 -17
  7. package/lib/matchers/browser/toHaveTitle.js +12 -23
  8. package/lib/matchers/browser/toHaveTitleContaining.js +3 -11
  9. package/lib/matchers/browser/toHaveUrl.js +12 -23
  10. package/lib/matchers/browser/toHaveUrlContaining.js +3 -11
  11. package/lib/matchers/element/toBeClickable.js +10 -21
  12. package/lib/matchers/element/toBeDisabled.js +3 -14
  13. package/lib/matchers/element/toBeDisplayed.js +10 -21
  14. package/lib/matchers/element/toBeDisplayedInViewport.js +10 -21
  15. package/lib/matchers/element/toBeEnabled.js +3 -14
  16. package/lib/matchers/element/toBeExisting.js +14 -27
  17. package/lib/matchers/element/toBeFocused.js +3 -14
  18. package/lib/matchers/element/toBeSelected.js +6 -19
  19. package/lib/matchers/element/toHaveAttribute.js +35 -46
  20. package/lib/matchers/element/toHaveAttributeContaining.js +4 -12
  21. package/lib/matchers/element/toHaveChildren.js +27 -39
  22. package/lib/matchers/element/toHaveClass.js +47 -0
  23. package/lib/matchers/element/toHaveClassContaining.js +10 -0
  24. package/lib/matchers/element/toHaveElementProperty.js +25 -36
  25. package/lib/matchers/element/toHaveHref.js +4 -13
  26. package/lib/matchers/element/toHaveHrefContaining.js +4 -12
  27. package/lib/matchers/element/toHaveId.js +3 -12
  28. package/lib/matchers/element/toHaveStyle.js +17 -28
  29. package/lib/matchers/element/toHaveText.js +18 -29
  30. package/lib/matchers/element/toHaveTextContaining.js +3 -11
  31. package/lib/matchers/element/toHaveValue.js +3 -12
  32. package/lib/matchers/element/toHaveValueContaining.js +3 -11
  33. package/lib/matchers/elements/toBeElementsArrayOfSize.js +16 -26
  34. package/lib/matchers/mock/toBeRequested.js +3 -11
  35. package/lib/matchers/mock/toBeRequestedTimes.js +17 -32
  36. package/lib/matchers/mock/toBeRequestedWith.js +30 -39
  37. package/lib/matchers.js +62 -35
  38. package/lib/types.js +1 -0
  39. package/lib/util/elementsUtil.js +2 -7
  40. package/lib/util/executeCommand.js +3 -7
  41. package/lib/util/formatMessage.js +17 -26
  42. package/lib/util/refetchElements.js +2 -8
  43. package/lib/utils.js +41 -49
  44. package/package.json +49 -44
  45. package/types/expect-webdriverio.d.ts +23 -22
  46. package/types/jest-global.d.ts +1 -1
  47. package/types/standalone.d.ts +2 -2
  48. package/lib/addMatchers.js +0 -48
  49. package/lib/matchers/element/toHaveElementClass.js +0 -60
  50. package/lib/matchers/element/toHaveElementClassContaining.js +0 -20
  51. package/lib/matchers/mock/toBeRequestedWithResponse.js +0 -13
  52. package/lib/options.js +0 -33
  53. package/lib/util/expectAdapter.js +0 -41
  54. package/types/standalone-global.d.ts +0 -9
package/README.md CHANGED
@@ -22,21 +22,41 @@ NOTE: [WebdriverIO](https://github.com/webdriverio/webdriverio) `v5.16.11` or hi
22
22
 
23
23
  ## Usage
24
24
 
25
- In your `wdio.conf.js`
26
- ```js
27
- before () { // not needed in WebdriverIO v6
28
- require('expect-webdriverio')
29
- },
30
- ```
25
+ ### Using WebdriverIO Testrunner
26
+
27
+ If you run your tests through the [WDIO testrunner](https://webdriver.io/docs/clioptions) no additional setup is needed. WebdriverIO initialises `expect-webdriverio` and makes `expect` available in the global scope. So you can use it directly in your tests:
31
28
 
32
- In your test
33
29
  ```js
34
- const $button = $('button')
35
- expect($button).toBeDisplayed()
30
+ const $button = await $('button')
31
+ await expect($button).toBeDisplayed()
36
32
  ```
37
33
 
38
34
  See more [Examples](docs/Examples.md)
39
35
 
36
+ ### Using in a standalone script
37
+
38
+ If you embed WebdriverIO in a standalone script, make sure you import `expect-webdriverio` before you use it anywhere.
39
+
40
+ ```js
41
+ import { remote } from 'webdriverio'
42
+ import { expect } from 'expect-webdriverio'
43
+
44
+ ;(async () => {
45
+ const browser = await remote({
46
+ capabilities: {
47
+ browserName: 'chrome'
48
+ }
49
+ })
50
+
51
+ await browser.url('https://webdriver.io')
52
+
53
+ const $button = await browser.$('button')
54
+ await expect($button).toBeDisplayed()
55
+
56
+ await browser.deleteSession()
57
+ })().catch(console.error)
58
+ ```
59
+
40
60
  ## API
41
61
 
42
62
  Please see [API doc](docs/API.md)
package/jasmine.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  /// <reference types="expect-webdriverio/types/expect-webdriverio"/>
2
2
 
3
3
  declare module jasmine {
4
- interface Matchers<T> extends ExpectWebdriverIO.Matchers<any, T> {}
5
4
  interface AsyncMatchers<T, U> extends ExpectWebdriverIO.Matchers<Promise<void>, T> {}
6
5
  }
package/jest.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- /// <reference types="expect-webdriverio/types/expect-webdriverio"/>
1
+ /// <reference types="./types/expect-webdriverio"/>
2
2
 
3
3
  declare namespace jest {
4
4
  interface Matchers<R, T> extends ExpectWebdriverIO.Matchers<R, T> { }
@@ -0,0 +1,4 @@
1
+ export const DEFAULT_OPTIONS = {
2
+ wait: 2000,
3
+ interval: 100,
4
+ };
package/lib/index.js CHANGED
@@ -1,6 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setOptions = void 0;
4
- const addMatchers_1 = require("./addMatchers");
5
- addMatchers_1.addMatchers();
6
- exports.setOptions = require('./options').setDefaultOptions;
1
+ import { expect as expectLib } from 'expect';
2
+ import matchers from './matchers.js';
3
+ import { DEFAULT_OPTIONS } from './constants.js';
4
+ expectLib.extend({ ...matchers });
5
+ export const expect = expectLib;
6
+ export const getConfig = () => DEFAULT_OPTIONS;
7
+ export const setDefaultOptions = (options = {}) => {
8
+ Object.entries(options).forEach(([key, value]) => {
9
+ if (key in DEFAULT_OPTIONS) {
10
+ DEFAULT_OPTIONS[key] = value;
11
+ }
12
+ });
13
+ };
14
+ export const setOptions = setDefaultOptions;
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isImmutableUnorderedSet = exports.isImmutableUnorderedKeyed = exports.hasProperty = exports.isUndefined = exports.fnNameFor = exports.isA = exports.equals = void 0;
4
- function equals(a, b, customTesters, strictCheck) {
1
+ export function equals(a, b, customTesters, strictCheck) {
5
2
  customTesters = customTesters || [];
6
3
  return eq(a, b, [], [], customTesters, strictCheck ? hasKey : hasDefinedKey);
7
4
  }
8
- exports.equals = equals;
9
5
  const functionToString = Function.prototype.toString;
10
6
  function isAsymmetric(obj) {
11
7
  return !!obj && isA('Function', obj.asymmetricMatch);
@@ -144,10 +140,9 @@ function hasDefinedKey(obj, key) {
144
140
  function hasKey(obj, key) {
145
141
  return Object.prototype.hasOwnProperty.call(obj, key);
146
142
  }
147
- function isA(typeName, value) {
143
+ export function isA(typeName, value) {
148
144
  return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
149
145
  }
150
- exports.isA = isA;
151
146
  function isDomNode(obj) {
152
147
  return (obj !== null &&
153
148
  typeof obj === 'object' &&
@@ -155,7 +150,7 @@ function isDomNode(obj) {
155
150
  typeof obj.nodeName === 'string' &&
156
151
  typeof obj.isEqualNode === 'function');
157
152
  }
158
- function fnNameFor(func) {
153
+ export function fnNameFor(func) {
159
154
  if (func.name) {
160
155
  return func.name;
161
156
  }
@@ -164,11 +159,9 @@ function fnNameFor(func) {
164
159
  .match(/^(?:async)?\s*function\s*\*?\s*([\w$]+)\s*\(/);
165
160
  return matches ? matches[1] : '<anonymous>';
166
161
  }
167
- exports.fnNameFor = fnNameFor;
168
- function isUndefined(obj) {
162
+ export function isUndefined(obj) {
169
163
  return obj === void 0;
170
164
  }
171
- exports.isUndefined = isUndefined;
172
165
  function getPrototype(obj) {
173
166
  if (Object.getPrototypeOf) {
174
167
  return Object.getPrototypeOf(obj);
@@ -178,7 +171,7 @@ function getPrototype(obj) {
178
171
  }
179
172
  return obj.constructor.prototype;
180
173
  }
181
- function hasProperty(obj, property) {
174
+ export function hasProperty(obj, property) {
182
175
  if (!obj) {
183
176
  return false;
184
177
  }
@@ -187,19 +180,16 @@ function hasProperty(obj, property) {
187
180
  }
188
181
  return hasProperty(getPrototype(obj), property);
189
182
  }
190
- exports.hasProperty = hasProperty;
191
183
  const IS_KEYED_SENTINEL = '@@__IMMUTABLE_KEYED__@@';
192
184
  const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@';
193
185
  const IS_ORDERED_SENTINEL = '@@__IMMUTABLE_ORDERED__@@';
194
- function isImmutableUnorderedKeyed(maybeKeyed) {
186
+ export function isImmutableUnorderedKeyed(maybeKeyed) {
195
187
  return !!(maybeKeyed &&
196
188
  maybeKeyed[IS_KEYED_SENTINEL] &&
197
189
  !maybeKeyed[IS_ORDERED_SENTINEL]);
198
190
  }
199
- exports.isImmutableUnorderedKeyed = isImmutableUnorderedKeyed;
200
- function isImmutableUnorderedSet(maybeSet) {
191
+ export function isImmutableUnorderedSet(maybeSet) {
201
192
  return !!(maybeSet &&
202
193
  maybeSet[IS_SET_SENTINEL] &&
203
194
  !maybeSet[IS_ORDERED_SENTINEL]);
204
195
  }
205
- exports.isImmutableUnorderedSet = isImmutableUnorderedSet;
@@ -1,26 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveTitle = exports.toHaveTitleFn = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const utils_1 = require("../../utils");
6
- function toHaveTitleFn(browser, title, options = {}) {
1
+ import { waitUntil, enhanceError, compareText } from '../../utils.js';
2
+ export async function toHaveTitle(browser, title, options = {}) {
7
3
  const isNot = this.isNot;
8
4
  const { expectation = 'title', verb = 'have' } = this;
9
- return browser.call(async () => {
10
- let actual;
11
- const pass = await utils_1.waitUntil(async () => {
12
- actual = await browser.getTitle();
13
- return utils_1.compareText(actual, title, options).result;
14
- }, isNot, options);
15
- const message = utils_1.enhanceError('window', title, actual, this, verb, expectation, '', options);
16
- return {
17
- pass,
18
- message: () => message
19
- };
20
- });
5
+ let actual;
6
+ const pass = await waitUntil(async () => {
7
+ actual = await browser.getTitle();
8
+ return compareText(actual, title, options).result;
9
+ }, isNot, options);
10
+ const message = enhanceError('window', title, actual, this, verb, expectation, '', options);
11
+ return {
12
+ pass,
13
+ message: () => message
14
+ };
21
15
  }
22
- exports.toHaveTitleFn = toHaveTitleFn;
23
- function toHaveTitle(...args) {
24
- return expectAdapter_1.runExpect.call(this, toHaveTitleFn, args);
25
- }
26
- exports.toHaveTitle = toHaveTitle;
@@ -1,15 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveTitleContaining = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveTitle_1 = require("./toHaveTitle");
6
- function toHaveTitleContainingFn(browser, title, options = {}) {
7
- return toHaveTitle_1.toHaveTitleFn.call(this, browser, title, {
1
+ import { toHaveTitle } from './toHaveTitle.js';
2
+ export function toHaveTitleContaining(browser, title, options = {}) {
3
+ return toHaveTitle.call(this, browser, title, {
8
4
  ...options,
9
5
  containing: true
10
6
  });
11
7
  }
12
- function toHaveTitleContaining(...args) {
13
- return expectAdapter_1.runExpect.call(this, toHaveTitleContainingFn, args);
14
- }
15
- exports.toHaveTitleContaining = toHaveTitleContaining;
@@ -1,26 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveUrl = exports.toHaveUrlFn = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const utils_1 = require("../../utils");
6
- function toHaveUrlFn(browser, url, options = {}) {
1
+ import { waitUntil, enhanceError, compareText } from '../../utils.js';
2
+ export async function toHaveUrl(browser, url, options = {}) {
7
3
  const isNot = this.isNot;
8
4
  const { expectation = 'url', verb = 'have' } = this;
9
- return browser.call(async () => {
10
- let actual;
11
- const pass = await utils_1.waitUntil(async () => {
12
- actual = await browser.getUrl();
13
- return utils_1.compareText(actual, url, options).result;
14
- }, isNot, options);
15
- const message = utils_1.enhanceError('window', url, actual, this, verb, expectation, '', options);
16
- return {
17
- pass,
18
- message: () => message
19
- };
20
- });
5
+ let actual;
6
+ const pass = await waitUntil(async () => {
7
+ actual = await browser.getUrl();
8
+ return compareText(actual, url, options).result;
9
+ }, isNot, options);
10
+ const message = enhanceError('window', url, actual, this, verb, expectation, '', options);
11
+ return {
12
+ pass,
13
+ message: () => message
14
+ };
21
15
  }
22
- exports.toHaveUrlFn = toHaveUrlFn;
23
- function toHaveUrl(...args) {
24
- return expectAdapter_1.runExpect.call(this, toHaveUrlFn, args);
25
- }
26
- exports.toHaveUrl = toHaveUrl;
@@ -1,15 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveUrlContaining = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveUrl_1 = require("./toHaveUrl");
6
- function toHaveUrlContainingFn(browser, url, options = {}) {
7
- return toHaveUrl_1.toHaveUrlFn.call(this, browser, url, {
1
+ import { toHaveUrl } from './toHaveUrl.js';
2
+ export function toHaveUrlContaining(browser, url, options = {}) {
3
+ return toHaveUrl.call(this, browser, url, {
8
4
  ...options,
9
5
  containing: true
10
6
  });
11
7
  }
12
- function toHaveUrlContaining(...args) {
13
- return expectAdapter_1.runExpect.call(this, toHaveUrlContainingFn, args);
14
- }
15
- exports.toHaveUrlContaining = toHaveUrlContaining;
@@ -1,23 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeClickable = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeClickableFn(received, options = {}) {
1
+ import { executeCommandBe } from '../../utils.js';
2
+ export function toBeClickable(received, options = {}) {
7
3
  this.expectation = this.expectation || 'clickable';
8
- return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
10
- try {
11
- return el.isClickable();
12
- }
13
- catch (_a) {
14
- return false;
15
- }
16
- }, options);
17
- return result;
18
- });
4
+ return executeCommandBe.call(this, received, async (el) => {
5
+ try {
6
+ return el.isClickable();
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ }, options);
19
12
  }
20
- function toBeClickable(...args) {
21
- return expectAdapter_1.runExpect.call(this, toBeClickableFn, args);
22
- }
23
- exports.toBeClickable = toBeClickable;
@@ -1,16 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeDisabled = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeDisabledFn(received, options = {}) {
1
+ import { executeCommandBe } from '../../utils.js';
2
+ export function toBeDisabled(received, options = {}) {
7
3
  this.expectation = this.expectation || 'disabled';
8
- return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
10
- return result;
11
- });
4
+ return executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
12
5
  }
13
- function toBeDisabled(...args) {
14
- return expectAdapter_1.runExpect.call(this, toBeDisabledFn, args);
15
- }
16
- exports.toBeDisabled = toBeDisabled;
@@ -1,23 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeDisplayed = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeDisplayedFn(received, options = {}) {
1
+ import { executeCommandBe } from '../../utils.js';
2
+ export async function toBeDisplayed(received, options = {}) {
7
3
  this.expectation = this.expectation || 'displayed';
8
- return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
10
- try {
11
- return el.isDisplayed();
12
- }
13
- catch (_a) {
14
- return false;
15
- }
16
- }, options);
17
- return result;
18
- });
4
+ return executeCommandBe.call(this, received, async (el) => {
5
+ try {
6
+ return el.isDisplayed();
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ }, options);
19
12
  }
20
- function toBeDisplayed(...args) {
21
- return expectAdapter_1.runExpect.call(this, toBeDisplayedFn, args);
22
- }
23
- exports.toBeDisplayed = toBeDisplayed;
@@ -1,23 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeDisplayedInViewport = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeDisplayedInViewportFn(received, options = {}) {
1
+ import { executeCommandBe } from '../../utils.js';
2
+ export function toBeDisplayedInViewport(received, options = {}) {
7
3
  this.expectation = this.expectation || 'displayed in viewport';
8
- return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
10
- try {
11
- return el.isDisplayedInViewport();
12
- }
13
- catch (_a) {
14
- return false;
15
- }
16
- }, options);
17
- return result;
18
- });
4
+ return executeCommandBe.call(this, received, async (el) => {
5
+ try {
6
+ return el.isDisplayedInViewport();
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ }, options);
19
12
  }
20
- function toBeDisplayedInViewport(...args) {
21
- return expectAdapter_1.runExpect.call(this, toBeDisplayedInViewportFn, args);
22
- }
23
- exports.toBeDisplayedInViewport = toBeDisplayedInViewport;
@@ -1,16 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeEnabled = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeEnabledFn(received, options = {}) {
1
+ import { executeCommandBe } from '../../utils.js';
2
+ export function toBeEnabled(received, options = {}) {
7
3
  this.expectation = this.expectation || 'enabled';
8
- return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, el => el.isEnabled(), options);
10
- return result;
11
- });
4
+ return executeCommandBe.call(this, received, el => el.isEnabled(), options);
12
5
  }
13
- function toBeEnabled(...args) {
14
- return expectAdapter_1.runExpect.call(this, toBeEnabledFn, args);
15
- }
16
- exports.toBeEnabled = toBeEnabled;
@@ -1,32 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBePresent = exports.toBeExisting = exports.toExist = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toExistFn(received, options = {}) {
1
+ import { executeCommandBe, aliasFn } from '../../utils.js';
2
+ export function toExist(received, options = {}) {
7
3
  this.expectation = this.expectation || 'exist';
8
4
  this.verb = this.verb || '';
9
- return browser.call(async () => {
10
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
11
- try {
12
- return el.isExisting();
13
- }
14
- catch (_a) {
15
- return false;
16
- }
17
- }, options);
18
- return result;
19
- });
5
+ return executeCommandBe.call(this, received, async (el) => {
6
+ try {
7
+ return el.isExisting();
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }, options);
20
13
  }
21
- function toExist(...args) {
22
- return expectAdapter_1.runExpect.call(this, toExistFn, args);
14
+ export function toBeExisting(el, options) {
15
+ return aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
23
16
  }
24
- exports.toExist = toExist;
25
- function toBeExisting(el, options) {
26
- return utils_1.aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
17
+ export function toBePresent(el, options) {
18
+ return aliasFn.call(this, toExist, { verb: 'be', expectation: 'present' }, el, options);
27
19
  }
28
- exports.toBeExisting = toBeExisting;
29
- function toBePresent(el, options) {
30
- return utils_1.aliasFn.call(this, toExist, { verb: 'be', expectation: 'present' }, el, options);
31
- }
32
- exports.toBePresent = toBePresent;
@@ -1,16 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeFocused = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeFocusedFn(received, options = {}) {
1
+ import { executeCommandBe } from '../../utils.js';
2
+ export function toBeFocused(received, options = {}) {
7
3
  this.expectation = this.expectation || 'focused';
8
- return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, el => el.isFocused(), options);
10
- return result;
11
- });
4
+ return executeCommandBe.call(this, received, el => el.isFocused(), options);
12
5
  }
13
- function toBeFocused(...args) {
14
- return expectAdapter_1.runExpect.call(this, toBeFocusedFn, args);
15
- }
16
- exports.toBeFocused = toBeFocused;
@@ -1,22 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeChecked = exports.toBeSelected = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeSelectedFn(received, options = {}) {
1
+ import { executeCommandBe } from '../../utils.js';
2
+ export function toBeSelected(received, options = {}) {
7
3
  this.expectation = this.expectation || 'selected';
8
- return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, el => el.isSelected(), options);
10
- return result;
11
- });
4
+ return executeCommandBe.call(this, received, el => el.isSelected(), options);
12
5
  }
13
- function toBeSelected(...args) {
14
- return expectAdapter_1.runExpect.call(this, toBeSelectedFn, args);
6
+ export function toBeChecked(el, options) {
7
+ this.expectation = 'checked';
8
+ return toBeSelected.call(this, el, options);
15
9
  }
16
- exports.toBeSelected = toBeSelected;
17
- function toBeChecked(el, options) {
18
- const context = expectAdapter_1.getContext(this);
19
- context.expectation = 'checked';
20
- return toBeSelected.call(context, el, options);
21
- }
22
- exports.toBeChecked = toBeChecked;
@@ -1,8 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveAttr = exports.toHaveAttribute = exports.toHaveAttributeFn = exports.toHaveAttributeAndValueFn = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
1
+ import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
6
2
  async function conditionAttr(el, attribute) {
7
3
  const attr = await el.getAttribute(attribute);
8
4
  if (typeof attr !== 'string') {
@@ -17,56 +13,49 @@ async function conditionAttrAndValue(el, attribute, value, options) {
17
13
  if (typeof attr !== 'string') {
18
14
  return { result: false, value: attr };
19
15
  }
20
- return utils_1.compareText(attr, value, options);
16
+ return compareText(attr, value, options);
21
17
  }
22
- function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
18
+ export async function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
23
19
  const isNot = this.isNot;
24
20
  const { expectation = 'attribute', verb = 'have' } = this;
25
- return browser.call(async () => {
26
- let el = await received;
27
- let attr;
28
- const pass = await utils_1.waitUntil(async () => {
29
- const result = await utils_1.executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options]);
30
- el = result.el;
31
- attr = result.values;
32
- return result.success;
33
- }, isNot, options);
34
- utils_1.updateElementsArray(pass, received, el);
35
- const expected = utils_1.wrapExpectedWithArray(el, attr, value);
36
- const message = utils_1.enhanceError(el, expected, attr, this, verb, expectation, attribute, options);
37
- return {
38
- pass,
39
- message: () => message
40
- };
41
- });
21
+ let el = await received;
22
+ let attr;
23
+ const pass = await waitUntil(async () => {
24
+ const result = await executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options]);
25
+ el = result.el;
26
+ attr = result.values;
27
+ return result.success;
28
+ }, isNot, options);
29
+ updateElementsArray(pass, received, el);
30
+ const expected = wrapExpectedWithArray(el, attr, value);
31
+ const message = enhanceError(el, expected, attr, this, verb, expectation, attribute, options);
32
+ return {
33
+ pass,
34
+ message: () => message
35
+ };
42
36
  }
43
- exports.toHaveAttributeAndValueFn = toHaveAttributeAndValueFn;
44
- function toHaveAttributeFn(received, attribute) {
37
+ export async function toHaveAttributeFn(received, attribute) {
45
38
  const isNot = this.isNot;
46
39
  const { expectation = 'attribute', verb = 'have' } = this;
47
- return browser.call(async () => {
48
- let el = await received;
49
- const pass = await utils_1.waitUntil(async () => {
50
- const result = await utils_1.executeCommand.call(this, el, conditionAttr, {}, [attribute]);
51
- el = result.el;
52
- return result.success;
53
- }, isNot, {});
54
- utils_1.updateElementsArray(pass, received, el);
55
- const message = utils_1.enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {});
56
- return {
57
- pass,
58
- message: () => message
59
- };
60
- });
40
+ let el = await received;
41
+ const pass = await waitUntil(async () => {
42
+ const result = await executeCommand.call(this, el, conditionAttr, {}, [attribute]);
43
+ el = result.el;
44
+ return result.success;
45
+ }, isNot, {});
46
+ updateElementsArray(pass, received, el);
47
+ const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {});
48
+ return {
49
+ pass,
50
+ message: () => message
51
+ };
61
52
  }
62
- exports.toHaveAttributeFn = toHaveAttributeFn;
63
- function toHaveAttribute(...args) {
53
+ export function toHaveAttribute(...args) {
64
54
  if (args.length === 3 || args.length === 4) {
65
- return expectAdapter_1.runExpect.call(this, toHaveAttributeAndValueFn, args);
55
+ return toHaveAttributeAndValueFn.call(this, ...args);
66
56
  }
67
57
  else {
68
- return expectAdapter_1.runExpect.call(this, toHaveAttributeFn, args);
58
+ return toHaveAttributeFn.call(this, ...args);
69
59
  }
70
60
  }
71
- exports.toHaveAttribute = toHaveAttribute;
72
- exports.toHaveAttr = toHaveAttribute;
61
+ export const toHaveAttr = toHaveAttribute;