expect-webdriverio 3.4.0 → 4.0.0-alpha.2

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 (52) hide show
  1. package/jest.d.ts +1 -1
  2. package/lib/constants.js +4 -0
  3. package/lib/index.js +15 -6
  4. package/lib/jasmineUtils.js +7 -17
  5. package/lib/matchers/browser/toHaveTitle.js +5 -14
  6. package/lib/matchers/browser/toHaveTitleContaining.js +3 -11
  7. package/lib/matchers/browser/toHaveUrl.js +5 -14
  8. package/lib/matchers/browser/toHaveUrlContaining.js +3 -11
  9. package/lib/matchers/element/toBeClickable.js +5 -12
  10. package/lib/matchers/element/toBeDisabled.js +4 -11
  11. package/lib/matchers/element/toBeDisplayed.js +5 -12
  12. package/lib/matchers/element/toBeDisplayedInViewport.js +5 -12
  13. package/lib/matchers/element/toBeEnabled.js +4 -11
  14. package/lib/matchers/element/toBeExisting.js +9 -18
  15. package/lib/matchers/element/toBeFocused.js +4 -11
  16. package/lib/matchers/element/toBeSelected.js +7 -16
  17. package/lib/matchers/element/toHaveAttribute.js +18 -24
  18. package/lib/matchers/element/toHaveAttributeContaining.js +4 -12
  19. package/lib/matchers/element/toHaveChildren.js +12 -19
  20. package/lib/matchers/element/{toHaveElementClass.js → toHaveClass.js} +10 -19
  21. package/lib/matchers/element/toHaveClassContaining.js +10 -0
  22. package/lib/matchers/element/toHaveElementProperty.js +10 -18
  23. package/lib/matchers/element/toHaveHref.js +4 -13
  24. package/lib/matchers/element/toHaveHrefContaining.js +4 -12
  25. package/lib/matchers/element/toHaveId.js +3 -12
  26. package/lib/matchers/element/toHaveStyle.js +8 -16
  27. package/lib/matchers/element/toHaveText.js +9 -17
  28. package/lib/matchers/element/toHaveTextContaining.js +3 -11
  29. package/lib/matchers/element/toHaveValue.js +3 -12
  30. package/lib/matchers/element/toHaveValueContaining.js +3 -11
  31. package/lib/matchers/elements/toBeElementsArrayOfSize.js +10 -17
  32. package/lib/matchers/mock/toBeRequested.js +3 -11
  33. package/lib/matchers/mock/toBeRequestedTimes.js +8 -16
  34. package/lib/matchers/mock/toBeRequestedWith.js +13 -19
  35. package/lib/matchers.js +62 -35
  36. package/lib/types.js +1 -0
  37. package/lib/util/elementsUtil.js +2 -7
  38. package/lib/util/executeCommand.js +3 -7
  39. package/lib/util/formatMessage.js +17 -26
  40. package/lib/util/refetchElements.js +2 -8
  41. package/lib/utils.js +15 -32
  42. package/package.json +51 -42
  43. package/types/expect-webdriverio.d.ts +1 -0
  44. package/types/jest-global.d.ts +1 -1
  45. package/types/standalone.d.ts +1 -1
  46. package/jasmine.d.ts +0 -6
  47. package/lib/addMatchers.js +0 -48
  48. package/lib/matchers/element/toHaveElementClassContaining.js +0 -20
  49. package/lib/matchers/mock/toBeRequestedWithResponse.js +0 -13
  50. package/lib/options.js +0 -33
  51. package/lib/util/expectAdapter.js +0 -41
  52. package/types/standalone-global.d.ts +0 -12
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,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setOptions = void 0;
4
- const addMatchers_1 = require("./addMatchers");
5
- (0, addMatchers_1.addMatchers)();
6
- exports.setOptions = require('./options').setDefaultOptions;
1
+ import expectLib from 'expect';
2
+ import matchers from './matchers.js';
3
+ import { DEFAULT_OPTIONS } from './constants.js';
4
+ export const getConfig = () => DEFAULT_OPTIONS;
5
+ export const setDefaultOptions = (options = {}) => {
6
+ Object.entries(options).forEach(([key, value]) => {
7
+ if (key in DEFAULT_OPTIONS) {
8
+ DEFAULT_OPTIONS[key] = value;
9
+ }
10
+ });
11
+ };
12
+ export const expect = async () => {
13
+ return expectLib.extend({ ...matchers });
14
+ };
15
+ 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,17 @@
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 function toHaveTitle(browser, title, options = {}) {
7
3
  const isNot = this.isNot;
8
4
  const { expectation = 'title', verb = 'have' } = this;
9
5
  return browser.call(async () => {
10
6
  let actual;
11
- const pass = await (0, utils_1.waitUntil)(async () => {
7
+ const pass = await waitUntil(async () => {
12
8
  actual = await browser.getTitle();
13
- return (0, utils_1.compareText)(actual, title, options).result;
9
+ return compareText(actual, title, options).result;
14
10
  }, isNot, options);
15
- const message = (0, utils_1.enhanceError)('window', title, actual, this, verb, expectation, '', options);
11
+ const message = enhanceError('window', title, actual, this, verb, expectation, '', options);
16
12
  return {
17
13
  pass,
18
14
  message: () => message
19
15
  };
20
16
  });
21
17
  }
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,17 @@
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 function toHaveUrl(browser, url, options = {}) {
7
3
  const isNot = this.isNot;
8
4
  const { expectation = 'url', verb = 'have' } = this;
9
5
  return browser.call(async () => {
10
6
  let actual;
11
- const pass = await (0, utils_1.waitUntil)(async () => {
7
+ const pass = await waitUntil(async () => {
12
8
  actual = await browser.getUrl();
13
- return (0, utils_1.compareText)(actual, url, options).result;
9
+ return compareText(actual, url, options).result;
14
10
  }, isNot, options);
15
- const message = (0, utils_1.enhanceError)('window', url, actual, this, verb, expectation, '', options);
11
+ const message = enhanceError('window', url, actual, this, verb, expectation, '', options);
16
12
  return {
17
13
  pass,
18
14
  message: () => message
19
15
  };
20
16
  });
21
17
  }
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,16 @@
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 { browser } from '@wdio/globals';
2
+ import { executeCommandBe } from '../../utils.js';
3
+ export function toBeClickable(received, options = {}) {
7
4
  this.expectation = this.expectation || 'clickable';
8
5
  return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
6
+ const result = await executeCommandBe.call(this, received, async (el) => {
10
7
  try {
11
8
  return el.isClickable();
12
9
  }
13
- catch (_a) {
10
+ catch {
14
11
  return false;
15
12
  }
16
13
  }, options);
17
14
  return result;
18
15
  });
19
16
  }
20
- function toBeClickable(...args) {
21
- return expectAdapter_1.runExpect.call(this || {}, toBeClickableFn, args);
22
- }
23
- exports.toBeClickable = toBeClickable;
@@ -1,16 +1,9 @@
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 { browser } from '@wdio/globals';
2
+ import { executeCommandBe } from '../../utils.js';
3
+ export function toBeDisabled(received, options = {}) {
7
4
  this.expectation = this.expectation || 'disabled';
8
5
  return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
6
+ const result = await executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
10
7
  return result;
11
8
  });
12
9
  }
13
- function toBeDisabled(...args) {
14
- return expectAdapter_1.runExpect.call(this || {}, toBeDisabledFn, args);
15
- }
16
- exports.toBeDisabled = toBeDisabled;
@@ -1,23 +1,16 @@
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 { browser } from '@wdio/globals';
2
+ import { executeCommandBe } from '../../utils.js';
3
+ export function toBeDisplayed(received, options = {}) {
7
4
  this.expectation = this.expectation || 'displayed';
8
5
  return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
6
+ const result = await executeCommandBe.call(this, received, async (el) => {
10
7
  try {
11
8
  return el.isDisplayed();
12
9
  }
13
- catch (_a) {
10
+ catch {
14
11
  return false;
15
12
  }
16
13
  }, options);
17
14
  return result;
18
15
  });
19
16
  }
20
- function toBeDisplayed(...args) {
21
- return expectAdapter_1.runExpect.call(this || {}, toBeDisplayedFn, args);
22
- }
23
- exports.toBeDisplayed = toBeDisplayed;
@@ -1,23 +1,16 @@
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 { browser } from '@wdio/globals';
2
+ import { executeCommandBe } from '../../utils.js';
3
+ export function toBeDisplayedInViewport(received, options = {}) {
7
4
  this.expectation = this.expectation || 'displayed in viewport';
8
5
  return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
6
+ const result = await executeCommandBe.call(this, received, async (el) => {
10
7
  try {
11
8
  return el.isDisplayedInViewport();
12
9
  }
13
- catch (_a) {
10
+ catch {
14
11
  return false;
15
12
  }
16
13
  }, options);
17
14
  return result;
18
15
  });
19
16
  }
20
- function toBeDisplayedInViewport(...args) {
21
- return expectAdapter_1.runExpect.call(this || {}, toBeDisplayedInViewportFn, args);
22
- }
23
- exports.toBeDisplayedInViewport = toBeDisplayedInViewport;
@@ -1,16 +1,9 @@
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 { browser } from '@wdio/globals';
2
+ import { executeCommandBe } from '../../utils.js';
3
+ export function toBeEnabled(received, options = {}) {
7
4
  this.expectation = this.expectation || 'enabled';
8
5
  return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, el => el.isEnabled(), options);
6
+ const result = await executeCommandBe.call(this, received, el => el.isEnabled(), options);
10
7
  return result;
11
8
  });
12
9
  }
13
- function toBeEnabled(...args) {
14
- return expectAdapter_1.runExpect.call(this || {}, toBeEnabledFn, args);
15
- }
16
- exports.toBeEnabled = toBeEnabled;
@@ -1,32 +1,23 @@
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 { browser } from '@wdio/globals';
2
+ import { executeCommandBe, aliasFn } from '../../utils.js';
3
+ export function toExist(received, options = {}) {
7
4
  this.expectation = this.expectation || 'exist';
8
5
  this.verb = this.verb || '';
9
6
  return browser.call(async () => {
10
- const result = await utils_1.executeCommandBe.call(this, received, async (el) => {
7
+ const result = await executeCommandBe.call(this, received, async (el) => {
11
8
  try {
12
9
  return el.isExisting();
13
10
  }
14
- catch (_a) {
11
+ catch {
15
12
  return false;
16
13
  }
17
14
  }, options);
18
15
  return result;
19
16
  });
20
17
  }
21
- function toExist(...args) {
22
- return expectAdapter_1.runExpect.call(this || {}, toExistFn, args);
18
+ export function toBeExisting(el, options) {
19
+ return aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
23
20
  }
24
- exports.toExist = toExist;
25
- function toBeExisting(el, options) {
26
- return utils_1.aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
21
+ export function toBePresent(el, options) {
22
+ return aliasFn.call(this, toExist, { verb: 'be', expectation: 'present' }, el, options);
27
23
  }
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,9 @@
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 { browser } from '@wdio/globals';
2
+ import { executeCommandBe } from '../../utils.js';
3
+ export function toBeFocused(received, options = {}) {
7
4
  this.expectation = this.expectation || 'focused';
8
5
  return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, el => el.isFocused(), options);
6
+ const result = await executeCommandBe.call(this, received, el => el.isFocused(), options);
10
7
  return result;
11
8
  });
12
9
  }
13
- function toBeFocused(...args) {
14
- return expectAdapter_1.runExpect.call(this || {}, toBeFocusedFn, args);
15
- }
16
- exports.toBeFocused = toBeFocused;
@@ -1,22 +1,13 @@
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 { browser } from '@wdio/globals';
2
+ import { executeCommandBe } from '../../utils.js';
3
+ export function toBeSelected(received, options = {}) {
7
4
  this.expectation = this.expectation || 'selected';
8
5
  return browser.call(async () => {
9
- const result = await utils_1.executeCommandBe.call(this, received, el => el.isSelected(), options);
6
+ const result = await executeCommandBe.call(this, received, el => el.isSelected(), options);
10
7
  return result;
11
8
  });
12
9
  }
13
- function toBeSelected(...args) {
14
- return expectAdapter_1.runExpect.call(this || {}, toBeSelectedFn, args);
10
+ export function toBeChecked(el, options) {
11
+ this.expectation = 'checked';
12
+ return toBeSelected.call(this, el, options);
15
13
  }
16
- exports.toBeSelected = toBeSelected;
17
- function toBeChecked(el, options) {
18
- const context = (0, expectAdapter_1.getContext)(this);
19
- context.expectation = 'checked';
20
- return toBeSelected.call(context, el, options);
21
- }
22
- exports.toBeChecked = toBeChecked;
@@ -1,8 +1,5 @@
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 { browser } from '@wdio/globals';
2
+ import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
6
3
  async function conditionAttr(el, attribute) {
7
4
  const attr = await el.getAttribute(attribute);
8
5
  if (typeof attr !== 'string') {
@@ -17,56 +14,53 @@ async function conditionAttrAndValue(el, attribute, value, options) {
17
14
  if (typeof attr !== 'string') {
18
15
  return { result: false, value: attr };
19
16
  }
20
- return (0, utils_1.compareText)(attr, value, options);
17
+ return compareText(attr, value, options);
21
18
  }
22
- function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
19
+ export function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
23
20
  const isNot = this.isNot;
24
21
  const { expectation = 'attribute', verb = 'have' } = this;
25
22
  return browser.call(async () => {
26
23
  let el = await received;
27
24
  let attr;
28
- const pass = await (0, utils_1.waitUntil)(async () => {
29
- const result = await utils_1.executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options]);
25
+ const pass = await waitUntil(async () => {
26
+ const result = await executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options]);
30
27
  el = result.el;
31
28
  attr = result.values;
32
29
  return result.success;
33
30
  }, isNot, options);
34
- (0, utils_1.updateElementsArray)(pass, received, el);
35
- const expected = (0, utils_1.wrapExpectedWithArray)(el, attr, value);
36
- const message = (0, utils_1.enhanceError)(el, expected, attr, this, verb, expectation, attribute, options);
31
+ updateElementsArray(pass, received, el);
32
+ const expected = wrapExpectedWithArray(el, attr, value);
33
+ const message = enhanceError(el, expected, attr, this, verb, expectation, attribute, options);
37
34
  return {
38
35
  pass,
39
36
  message: () => message
40
37
  };
41
38
  });
42
39
  }
43
- exports.toHaveAttributeAndValueFn = toHaveAttributeAndValueFn;
44
- function toHaveAttributeFn(received, attribute) {
40
+ export function toHaveAttributeFn(received, attribute) {
45
41
  const isNot = this.isNot;
46
42
  const { expectation = 'attribute', verb = 'have' } = this;
47
43
  return browser.call(async () => {
48
44
  let el = await received;
49
- const pass = await (0, utils_1.waitUntil)(async () => {
50
- const result = await utils_1.executeCommand.call(this, el, conditionAttr, {}, [attribute]);
45
+ const pass = await waitUntil(async () => {
46
+ const result = await executeCommand.call(this, el, conditionAttr, {}, [attribute]);
51
47
  el = result.el;
52
48
  return result.success;
53
49
  }, isNot, {});
54
- (0, utils_1.updateElementsArray)(pass, received, el);
55
- const message = (0, utils_1.enhanceError)(el, !isNot, pass, this, verb, expectation, attribute, {});
50
+ updateElementsArray(pass, received, el);
51
+ const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {});
56
52
  return {
57
53
  pass,
58
54
  message: () => message
59
55
  };
60
56
  });
61
57
  }
62
- exports.toHaveAttributeFn = toHaveAttributeFn;
63
- function toHaveAttribute(...args) {
58
+ export function toHaveAttribute(...args) {
64
59
  if (args.length === 3 || args.length === 4) {
65
- return expectAdapter_1.runExpect.call(this || {}, toHaveAttributeAndValueFn, args);
60
+ return toHaveAttributeAndValueFn.call(this, ...args);
66
61
  }
67
62
  else {
68
- return expectAdapter_1.runExpect.call(this || {}, toHaveAttributeFn, args);
63
+ return toHaveAttributeFn.call(this, ...args);
69
64
  }
70
65
  }
71
- exports.toHaveAttribute = toHaveAttribute;
72
- exports.toHaveAttr = toHaveAttribute;
66
+ export const toHaveAttr = toHaveAttribute;
@@ -1,16 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveAttrContaining = exports.toHaveAttributeContaining = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveAttribute_1 = require("./toHaveAttribute");
6
- function toHaveAttributeContainingFn(el, attribute, value, options = {}) {
7
- return toHaveAttribute_1.toHaveAttributeAndValueFn.call(this, el, attribute, value, {
1
+ import { toHaveAttributeAndValueFn } from './toHaveAttribute.js';
2
+ export function toHaveAttributeContaining(el, attribute, value, options = {}) {
3
+ return toHaveAttributeAndValueFn.call(this, el, attribute, value, {
8
4
  ...options,
9
5
  containing: true
10
6
  });
11
7
  }
12
- function toHaveAttributeContaining(...args) {
13
- return expectAdapter_1.runExpect.call(this || {}, toHaveAttributeContainingFn, args);
14
- }
15
- exports.toHaveAttributeContaining = toHaveAttributeContaining;
16
- exports.toHaveAttrContaining = toHaveAttributeContaining;
8
+ export const toHaveAttrContaining = toHaveAttributeContaining;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveChildren = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
1
+ import { browser } from '@wdio/globals';
2
+ import { waitUntil, enhanceError, compareNumbers, numberError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
6
3
  async function condition(el, options) {
7
4
  const children = await el.$$('./*');
8
5
  if (typeof options.lte !== 'number' &&
@@ -10,15 +7,15 @@ async function condition(el, options) {
10
7
  typeof options.eq !== 'number') {
11
8
  return {
12
9
  result: children.length > 0,
13
- value: children === null || children === void 0 ? void 0 : children.length
10
+ value: children?.length
14
11
  };
15
12
  }
16
13
  return {
17
- result: (0, utils_1.compareNumbers)(children === null || children === void 0 ? void 0 : children.length, options),
18
- value: children === null || children === void 0 ? void 0 : children.length
14
+ result: compareNumbers(children?.length, options),
15
+ value: children?.length
19
16
  };
20
17
  }
21
- function toHaveChildrenFn(received, expected, options = {}) {
18
+ export function toHaveChildren(received, expected, options = {}) {
22
19
  const isNot = this.isNot;
23
20
  const { expectation = 'children', verb = 'have' } = this;
24
21
  let numberOptions;
@@ -31,23 +28,19 @@ function toHaveChildrenFn(received, expected, options = {}) {
31
28
  return browser.call(async () => {
32
29
  let el = await received;
33
30
  let children;
34
- const pass = await (0, utils_1.waitUntil)(async () => {
35
- const result = await utils_1.executeCommand.call(this, el, condition, numberOptions, [numberOptions]);
31
+ const pass = await waitUntil(async () => {
32
+ const result = await executeCommand.call(this, el, condition, numberOptions, [numberOptions]);
36
33
  el = result.el;
37
34
  children = result.values;
38
35
  return result.success;
39
36
  }, isNot, { ...numberOptions, ...options });
40
- (0, utils_1.updateElementsArray)(pass, received, el);
41
- const error = (0, utils_1.numberError)(numberOptions);
42
- const expected = (0, utils_1.wrapExpectedWithArray)(el, children, error);
43
- const message = (0, utils_1.enhanceError)(el, expected, children, this, verb, expectation, '', numberOptions);
37
+ updateElementsArray(pass, received, el);
38
+ const error = numberError(numberOptions);
39
+ const expected = wrapExpectedWithArray(el, children, error);
40
+ const message = enhanceError(el, expected, children, this, verb, expectation, '', numberOptions);
44
41
  return {
45
42
  pass,
46
43
  message: () => message
47
44
  };
48
45
  });
49
46
  }
50
- function toHaveChildren(...args) {
51
- return expectAdapter_1.runExpect.call(this || {}, toHaveChildrenFn, args);
52
- }
53
- exports.toHaveChildren = toHaveChildren;