expect-webdriverio 3.3.1 → 4.0.0-alpha.0

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 (51) 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 -44
  43. package/types/jest-global.d.ts +1 -1
  44. package/types/standalone.d.ts +2 -2
  45. package/jasmine.d.ts +0 -6
  46. package/lib/addMatchers.js +0 -48
  47. package/lib/matchers/element/toHaveElementClassContaining.js +0 -20
  48. package/lib/matchers/mock/toBeRequestedWithResponse.js +0 -13
  49. package/lib/options.js +0 -33
  50. package/lib/util/expectAdapter.js +0 -41
  51. package/types/standalone-global.d.ts +0 -12
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveClass = exports.toHaveElementClass = 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, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils';
6
3
  async function condition(el, attribute, value, options) {
7
4
  const { ignoreCase = false, trim = false, containing = false } = options;
8
5
  let attr = await el.getAttribute(attribute);
@@ -27,33 +24,27 @@ async function condition(el, attribute, value, options) {
27
24
  result: valueInClasses
28
25
  };
29
26
  }
30
- function toHaveElementClassFn(received, className, options = {}) {
27
+ export function toHaveElementClass(...args) {
28
+ return toHaveClass.call(this || {}, ...args);
29
+ }
30
+ export function toHaveClass(received, className, options = {}) {
31
31
  const isNot = this.isNot;
32
32
  const { expectation = 'class', verb = 'have' } = this;
33
33
  const attribute = 'class';
34
34
  return browser.call(async () => {
35
35
  let el = await received;
36
36
  let attr;
37
- const pass = await (0, utils_1.waitUntil)(async () => {
38
- const result = await utils_1.executeCommand.call(this, el, condition, options, [attribute, className, options]);
37
+ const pass = await waitUntil(async () => {
38
+ const result = await executeCommand.call(this, el, condition, options, [attribute, className, options]);
39
39
  el = result.el;
40
40
  attr = result.values;
41
41
  return result.success;
42
42
  }, isNot, options);
43
- (0, utils_1.updateElementsArray)(pass, received, el);
44
- const message = (0, utils_1.enhanceError)(el, (0, utils_1.wrapExpectedWithArray)(el, attr, className), attr, this, verb, expectation, '', options);
43
+ updateElementsArray(pass, received, el);
44
+ const message = enhanceError(el, wrapExpectedWithArray(el, attr, className), attr, this, verb, expectation, '', options);
45
45
  return {
46
46
  pass,
47
47
  message: () => message
48
48
  };
49
49
  });
50
50
  }
51
- function toHaveElementClass(...args) {
52
- return expectAdapter_1.runExpect.call(this || {}, toHaveElementClassFn, args);
53
- }
54
- exports.toHaveElementClass = toHaveElementClass;
55
- function toHaveClass(...args) {
56
- console.warn('expect(...).toHaveClass is deprecated and will be removed in next release. Use toHaveElementClass instead.');
57
- return expectAdapter_1.runExpect.call(this || {}, toHaveElementClassFn, args);
58
- }
59
- exports.toHaveClass = toHaveClass;
@@ -0,0 +1,10 @@
1
+ import { toHaveAttributeAndValueFn } from './toHaveAttribute';
2
+ export function toHaveElementClassContaining(...args) {
3
+ return toHaveClassContaining.call(this, ...args);
4
+ }
5
+ export function toHaveClassContaining(el, className, options = {}) {
6
+ return toHaveAttributeAndValueFn.call(this, el, 'class', className, {
7
+ ...options,
8
+ containing: true
9
+ });
10
+ }
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveElementProperty = exports.toHaveElementPropertyFn = 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';
6
3
  async function condition(el, property, value, options = {}) {
7
4
  const { asString = false } = options;
8
5
  let prop = await el.getProperty(property);
@@ -16,28 +13,28 @@ async function condition(el, property, value, options = {}) {
16
13
  return { result: prop === value, value: prop };
17
14
  }
18
15
  prop = prop.toString();
19
- return (0, utils_1.compareText)(prop, value, options);
16
+ return compareText(prop, value, options);
20
17
  }
21
- function toHaveElementPropertyFn(received, property, value, options = {}) {
18
+ export function toHaveElementProperty(received, property, value, options = {}) {
22
19
  const isNot = this.isNot;
23
20
  const { expectation = 'property', verb = 'have' } = this;
24
21
  return browser.call(async () => {
25
22
  let el = await received;
26
23
  let prop;
27
- const pass = await (0, utils_1.waitUntil)(async () => {
28
- const result = await utils_1.executeCommand.call(this, el, condition, options, [property, value]);
24
+ const pass = await waitUntil(async () => {
25
+ const result = await executeCommand.call(this, el, condition, options, [property, value]);
29
26
  el = result.el;
30
27
  prop = result.values;
31
28
  return result.success;
32
29
  }, isNot, options);
33
- (0, utils_1.updateElementsArray)(pass, received, el);
30
+ updateElementsArray(pass, received, el);
34
31
  let message;
35
32
  if (value === undefined) {
36
- message = (0, utils_1.enhanceError)(el, !isNot, pass, this, verb, expectation, property, options);
33
+ message = enhanceError(el, !isNot, pass, this, verb, expectation, property, options);
37
34
  }
38
35
  else {
39
- const expected = (0, utils_1.wrapExpectedWithArray)(el, prop, value);
40
- message = (0, utils_1.enhanceError)(el, expected, prop, this, verb, expectation, property, options);
36
+ const expected = wrapExpectedWithArray(el, prop, value);
37
+ message = enhanceError(el, expected, prop, this, verb, expectation, property, options);
41
38
  }
42
39
  return {
43
40
  pass,
@@ -45,8 +42,3 @@ function toHaveElementPropertyFn(received, property, value, options = {}) {
45
42
  };
46
43
  });
47
44
  }
48
- exports.toHaveElementPropertyFn = toHaveElementPropertyFn;
49
- function toHaveElementProperty(...args) {
50
- return expectAdapter_1.runExpect.call(this || {}, toHaveElementPropertyFn, args);
51
- }
52
- exports.toHaveElementProperty = toHaveElementProperty;
@@ -1,14 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveLink = exports.toHaveHref = exports.toHaveHrefFn = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveAttribute_1 = require("./toHaveAttribute");
6
- function toHaveHrefFn(el, href, options = {}) {
7
- return toHaveAttribute_1.toHaveAttributeAndValueFn.call(this, el, 'href', href, options);
1
+ import { toHaveAttributeAndValueFn } from './toHaveAttribute';
2
+ export function toHaveHref(el, href, options = {}) {
3
+ return toHaveAttributeAndValueFn.call(this, el, 'href', href, options);
8
4
  }
9
- exports.toHaveHrefFn = toHaveHrefFn;
10
- function toHaveHref(...args) {
11
- return expectAdapter_1.runExpect.call(this || {}, toHaveHrefFn, args);
12
- }
13
- exports.toHaveHref = toHaveHref;
14
- exports.toHaveLink = toHaveHref;
5
+ export const toHaveLink = toHaveHref;
@@ -1,16 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveLinkContaining = exports.toHaveHrefContaining = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveHref_1 = require("./toHaveHref");
6
- function toHaveHrefContainingFn(el, href, options = {}) {
7
- return toHaveHref_1.toHaveHrefFn.call(this, el, href, {
1
+ import { toHaveHref } from './toHaveHref';
2
+ export function toHaveHrefContaining(el, href, options = {}) {
3
+ return toHaveHref.call(this, el, href, {
8
4
  ...options,
9
5
  containing: true
10
6
  });
11
7
  }
12
- function toHaveHrefContaining(...args) {
13
- return expectAdapter_1.runExpect.call(this || {}, toHaveHrefContainingFn, args);
14
- }
15
- exports.toHaveHrefContaining = toHaveHrefContaining;
16
- exports.toHaveLinkContaining = toHaveHrefContaining;
8
+ export const toHaveLinkContaining = toHaveHrefContaining;
@@ -1,13 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveId = exports.toHaveIdFn = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveAttribute_1 = require("./toHaveAttribute");
6
- function toHaveIdFn(el, id, options = {}) {
7
- return toHaveAttribute_1.toHaveAttributeAndValueFn.call(this, el, 'id', id, options);
1
+ import { toHaveAttributeAndValueFn } from './toHaveAttribute';
2
+ export function toHaveId(el, id, options = {}) {
3
+ return toHaveAttributeAndValueFn.call(this, el, 'id', id, options);
8
4
  }
9
- exports.toHaveIdFn = toHaveIdFn;
10
- function toHaveId(...args) {
11
- return expectAdapter_1.runExpect.call(this || {}, toHaveIdFn, args);
12
- }
13
- exports.toHaveId = toHaveId;
@@ -1,33 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveStyle = exports.toHaveStyleFn = 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, compareStyle, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils';
6
3
  async function condition(el, style, options) {
7
- return (0, utils_1.compareStyle)(el, style, options);
4
+ return compareStyle(el, style, options);
8
5
  }
9
- function toHaveStyleFn(received, style, options = {}) {
6
+ export function toHaveStyle(received, style, options = {}) {
10
7
  const isNot = this.isNot;
11
8
  const { expectation = 'style', verb = 'have' } = this;
12
9
  return browser.call(async () => {
13
10
  let el = await received;
14
11
  let actualStyle;
15
- const pass = await (0, utils_1.waitUntil)(async () => {
16
- const result = await utils_1.executeCommand.call(this, el, condition, options, [style, options]);
12
+ const pass = await waitUntil(async () => {
13
+ const result = await executeCommand.call(this, el, condition, options, [style, options]);
17
14
  el = result.el;
18
15
  actualStyle = result.values;
19
16
  return result.success;
20
17
  }, isNot, options);
21
- (0, utils_1.updateElementsArray)(pass, received, el);
22
- const message = (0, utils_1.enhanceError)(el, (0, utils_1.wrapExpectedWithArray)(el, actualStyle, style), actualStyle, this, verb, expectation, '', options);
18
+ updateElementsArray(pass, received, el);
19
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualStyle, style), actualStyle, this, verb, expectation, '', options);
23
20
  return {
24
21
  pass,
25
22
  message: () => message
26
23
  };
27
24
  });
28
25
  }
29
- exports.toHaveStyleFn = toHaveStyleFn;
30
- function toHaveStyle(...args) {
31
- return expectAdapter_1.runExpect.call(this || {}, toHaveStyleFn, args);
32
- }
33
- exports.toHaveStyle = toHaveStyle;
@@ -1,37 +1,29 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveText = exports.toHaveTextFn = 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, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils';
6
3
  async function condition(el, text, options) {
7
4
  const actualText = await el.getText();
8
5
  if (Array.isArray(text)) {
9
- return (0, utils_1.compareTextWithArray)(actualText, text, options);
6
+ return compareTextWithArray(actualText, text, options);
10
7
  }
11
- return (0, utils_1.compareText)(actualText, text, options);
8
+ return compareText(actualText, text, options);
12
9
  }
13
- function toHaveTextFn(received, text, options = {}) {
10
+ export function toHaveText(received, text, options = {}) {
14
11
  const isNot = this.isNot;
15
12
  const { expectation = 'text', verb = 'have' } = this;
16
13
  return browser.call(async () => {
17
14
  let el = await received;
18
15
  let actualText;
19
- const pass = await (0, utils_1.waitUntil)(async () => {
20
- const result = await utils_1.executeCommand.call(this, el, condition, options, [text, options]);
16
+ const pass = await waitUntil(async () => {
17
+ const result = await executeCommand.call(this, el, condition, options, [text, options]);
21
18
  el = result.el;
22
19
  actualText = result.values;
23
20
  return result.success;
24
21
  }, isNot, options);
25
- (0, utils_1.updateElementsArray)(pass, received, el);
26
- const message = (0, utils_1.enhanceError)(el, (0, utils_1.wrapExpectedWithArray)(el, actualText, text), actualText, this, verb, expectation, '', options);
22
+ updateElementsArray(pass, received, el);
23
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualText, text), actualText, this, verb, expectation, '', options);
27
24
  return {
28
25
  pass,
29
26
  message: () => message
30
27
  };
31
28
  });
32
29
  }
33
- exports.toHaveTextFn = toHaveTextFn;
34
- function toHaveText(...args) {
35
- return expectAdapter_1.runExpect.call(this || {}, toHaveTextFn, args);
36
- }
37
- exports.toHaveText = toHaveText;
@@ -1,15 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveTextContaining = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveText_1 = require("./toHaveText");
6
- function toHaveTextContainingFn(el, text, options = {}) {
7
- return toHaveText_1.toHaveTextFn.call(this, el, text, {
1
+ import { toHaveText } from './toHaveText';
2
+ export function toHaveTextContaining(el, text, options = {}) {
3
+ return toHaveText.call(this, el, text, {
8
4
  ...options,
9
5
  containing: true
10
6
  });
11
7
  }
12
- function toHaveTextContaining(...args) {
13
- return expectAdapter_1.runExpect.call(this || {}, toHaveTextContainingFn, args);
14
- }
15
- exports.toHaveTextContaining = toHaveTextContaining;
@@ -1,13 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveValue = exports.toHaveValueFn = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveElementProperty_1 = require("./toHaveElementProperty");
6
- function toHaveValueFn(el, value, options = {}) {
7
- return toHaveElementProperty_1.toHaveElementPropertyFn.call(this, el, 'value', value, options);
1
+ import { toHaveElementProperty } from './toHaveElementProperty';
2
+ export function toHaveValue(el, value, options = {}) {
3
+ return toHaveElementProperty.call(this, el, 'value', value, options);
8
4
  }
9
- exports.toHaveValueFn = toHaveValueFn;
10
- function toHaveValue(...args) {
11
- return expectAdapter_1.runExpect.call(this || {}, toHaveValueFn, args);
12
- }
13
- exports.toHaveValue = toHaveValue;
@@ -1,15 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toHaveValueContaining = void 0;
4
- const expectAdapter_1 = require("../../util/expectAdapter");
5
- const toHaveValue_1 = require("./toHaveValue");
6
- function toHaveValueContainingFn(el, value, options = {}) {
7
- return toHaveValue_1.toHaveValueFn.call(this, el, value, {
1
+ import { toHaveValue } from './toHaveValue';
2
+ export function toHaveValueContaining(el, value, options = {}) {
3
+ return toHaveValue.call(this, el, value, {
8
4
  ...options,
9
5
  containing: true
10
6
  });
11
7
  }
12
- function toHaveValueContaining(...args) {
13
- return expectAdapter_1.runExpect.call(this || {}, toHaveValueContainingFn, args);
14
- }
15
- exports.toHaveValueContaining = toHaveValueContaining;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeElementsArrayOfSize = void 0;
4
- const utils_1 = require("../../utils");
5
- const refetchElements_1 = require("../../util/refetchElements");
6
- const expectAdapter_1 = require("../../util/expectAdapter");
7
- function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
1
+ import { browser } from '@wdio/globals';
2
+ import { waitUntil, enhanceError, compareNumbers, numberError, updateElementsArray } from '../../utils';
3
+ import { refetchElements } from '../../util/refetchElements';
4
+ export function toBeElementsArrayOfSize(received, expected, options = {}) {
8
5
  const isNot = this.isNot;
9
6
  const { expectation = 'elements array of size', verb = 'be' } = this;
10
7
  let numberOptions;
@@ -20,20 +17,16 @@ function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
20
17
  return browser.call(async () => {
21
18
  let elements = await received;
22
19
  const arrLength = elements.length;
23
- const pass = await (0, utils_1.waitUntil)(async () => {
24
- elements = await (0, refetchElements_1.refetchElements)(elements, numberOptions.wait, true);
25
- return (0, utils_1.compareNumbers)(elements.length, numberOptions);
20
+ const pass = await waitUntil(async () => {
21
+ elements = await refetchElements(elements, numberOptions.wait, true);
22
+ return compareNumbers(elements.length, numberOptions);
26
23
  }, isNot, { ...numberOptions, ...options });
27
- (0, utils_1.updateElementsArray)(pass, received, elements, true);
28
- const error = (0, utils_1.numberError)(numberOptions);
29
- const message = (0, utils_1.enhanceError)(elements, error, arrLength, this, verb, expectation, '', numberOptions);
24
+ updateElementsArray(pass, received, elements, true);
25
+ const error = numberError(numberOptions);
26
+ const message = enhanceError(elements, error, arrLength, this, verb, expectation, '', numberOptions);
30
27
  return {
31
28
  pass,
32
29
  message: () => message
33
30
  };
34
31
  });
35
32
  }
36
- function toBeElementsArrayOfSize(...args) {
37
- return expectAdapter_1.runExpect.call(this || {}, toBeElementsArrayOfSizeFn, args);
38
- }
39
- exports.toBeElementsArrayOfSize = toBeElementsArrayOfSize;
@@ -1,12 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeRequested = void 0;
4
- const toBeRequestedTimes_1 = require("./toBeRequestedTimes");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- function toBeRequestedFn(received, options = {}) {
7
- return toBeRequestedTimes_1.toBeRequestedTimes.call({ ...(this || {}), expectation: 'called' }, received, { ...options, gte: 1 });
1
+ import { toBeRequestedTimes } from './toBeRequestedTimes';
2
+ export function toBeRequested(received, options = {}) {
3
+ return toBeRequestedTimes.call({ ...(this || {}), expectation: 'called' }, received, { ...options, gte: 1 });
8
4
  }
9
- function toBeRequested(...args) {
10
- return expectAdapter_1.runExpect.call(this || {}, toBeRequestedFn, args);
11
- }
12
- exports.toBeRequested = toBeRequested;
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeRequestedTimes = exports.toBeRequestedTimesFn = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- const formatMessage_1 = require("../../util/formatMessage");
7
- function toBeRequestedTimesFn(received, expected = {}, options = {}) {
1
+ import { browser } from '@wdio/globals';
2
+ import { waitUntil, enhanceError, compareNumbers } from '../../utils';
3
+ import { numberError } from '../../util/formatMessage';
4
+ export function toBeRequestedTimes(received, expected = {}, options = {}) {
8
5
  const isNot = this.isNot || false;
9
6
  const { expectation = `called${typeof expected === 'number' ? ' ' + expected : ''} time${expected !== 1 ? 's' : ''}`, verb = 'be' } = this;
10
7
  let numberOptions;
@@ -16,20 +13,15 @@ function toBeRequestedTimesFn(received, expected = {}, options = {}) {
16
13
  }
17
14
  return browser.call(async () => {
18
15
  let actual;
19
- const pass = await (0, utils_1.waitUntil)(async () => {
16
+ const pass = await waitUntil(async () => {
20
17
  actual = received.calls.length;
21
- return (0, utils_1.compareNumbers)(actual, numberOptions);
18
+ return compareNumbers(actual, numberOptions);
22
19
  }, isNot, { ...numberOptions, ...options });
23
- const error = (0, formatMessage_1.numberError)(numberOptions);
24
- const message = (0, utils_1.enhanceError)('mock', error, actual, this, verb, expectation, '', numberOptions);
20
+ const error = numberError(numberOptions);
21
+ const message = enhanceError('mock', error, actual, this, verb, expectation, '', numberOptions);
25
22
  return {
26
23
  pass,
27
24
  message: () => message
28
25
  };
29
26
  });
30
27
  }
31
- exports.toBeRequestedTimesFn = toBeRequestedTimesFn;
32
- function toBeRequestedTimes(...args) {
33
- return expectAdapter_1.runExpect.call(this || {}, toBeRequestedTimesFn, args);
34
- }
35
- exports.toBeRequestedTimes = toBeRequestedTimes;
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toBeRequestedWith = exports.toBeRequestedWithFn = void 0;
4
- const utils_1 = require("../../utils");
5
- const expectAdapter_1 = require("../../util/expectAdapter");
6
- const jasmineUtils_1 = require("../../jasmineUtils");
1
+ import { browser } from '@wdio/globals';
2
+ import { waitUntil, enhanceError } from '../../utils';
3
+ import { equals } from '../../jasmineUtils';
7
4
  const STR_LIMIT = 80;
8
5
  const KEY_LIMIT = 12;
9
- function toBeRequestedWithFn(received, requestedWith = {}, options = {}) {
6
+ export function toBeRequestedWith(received, requestedWith = {}, options = {}) {
10
7
  const isNot = this.isNot || false;
11
8
  const { expectation = 'called with', verb = 'be' } = this;
12
9
  return browser.call(async () => {
13
10
  let actual;
14
- const pass = await (0, utils_1.waitUntil)(async () => {
11
+ const pass = await waitUntil(async () => {
15
12
  for (const call of received.calls) {
16
13
  actual = call;
17
14
  if (methodMatcher(call.method, requestedWith.method) &&
@@ -26,14 +23,13 @@ function toBeRequestedWithFn(received, requestedWith = {}, options = {}) {
26
23
  }
27
24
  return false;
28
25
  }, isNot, { ...options, wait: isNot ? 0 : options.wait });
29
- const message = (0, utils_1.enhanceError)('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
26
+ const message = enhanceError('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
30
27
  return {
31
28
  pass,
32
29
  message: () => message,
33
30
  };
34
31
  });
35
32
  }
36
- exports.toBeRequestedWithFn = toBeRequestedWithFn;
37
33
  const methodMatcher = (method, expected) => {
38
34
  if (typeof expected === 'undefined') {
39
35
  return true;
@@ -66,7 +62,7 @@ const urlMatcher = (url, expected) => {
66
62
  if (typeof expected === 'function') {
67
63
  return expected(url);
68
64
  }
69
- return (0, jasmineUtils_1.equals)(url, expected);
65
+ return equals(url, expected);
70
66
  };
71
67
  const headersMatcher = (headers, expected) => {
72
68
  if (typeof expected === 'undefined') {
@@ -75,7 +71,7 @@ const headersMatcher = (headers, expected) => {
75
71
  if (typeof expected === 'function') {
76
72
  return expected(headers);
77
73
  }
78
- return (0, jasmineUtils_1.equals)(headers, expected);
74
+ return equals(headers, expected);
79
75
  };
80
76
  const bodyMatcher = (body, expected) => {
81
77
  if (typeof expected === 'undefined') {
@@ -97,7 +93,7 @@ const bodyMatcher = (body, expected) => {
97
93
  return false;
98
94
  }
99
95
  }
100
- return (0, jasmineUtils_1.equals)(parsedBody, expected);
96
+ return equals(parsedBody, expected);
101
97
  };
102
98
  const isExpectedJsonLike = (expected) => {
103
99
  if (typeof expected === 'undefined') {
@@ -112,14 +108,13 @@ const isExpectedJsonLike = (expected) => {
112
108
  actualSample instanceof RegExp === false));
113
109
  };
114
110
  const isMatcher = (filter) => {
115
- var _a;
116
- return typeof ((_a = filter.__proto__) === null || _a === void 0 ? void 0 : _a.asymmetricMatch) === 'function';
111
+ return typeof filter.__proto__?.asymmetricMatch === 'function';
117
112
  };
118
113
  const tryParseBody = (jsonString, fallback = null) => {
119
114
  try {
120
115
  return typeof jsonString === 'undefined' ? fallback : JSON.parse(jsonString);
121
116
  }
122
- catch (_a) {
117
+ catch {
123
118
  return fallback;
124
119
  }
125
120
  };
@@ -212,7 +207,6 @@ const deleteUndefinedValues = (obj, baseline = obj) => {
212
207
  }
213
208
  });
214
209
  };
215
- function toBeRequestedWith(...args) {
216
- return expectAdapter_1.runExpect.call(this || {}, toBeRequestedWithFn, args);
210
+ export function toBeRequestedWithResponse(...args) {
211
+ return toBeRequestedWith.call(this, ...args);
217
212
  }
218
- exports.toBeRequestedWith = toBeRequestedWith;
package/lib/matchers.js CHANGED
@@ -1,41 +1,68 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ import * as toHaveTitle from './matchers/browser/toHaveTitle.js';
2
+ import * as toHaveTitleContaining from './matchers/browser/toHaveTitleContaining.js';
3
+ import * as toHaveUrl from './matchers/browser/toHaveUrl.js';
4
+ import * as toHaveUrlContaining from './matchers/browser/toHaveUrlContaining.js';
5
+ import * as toBeElementsArrayOfSize from './matchers/elements/toBeElementsArrayOfSize.js';
6
+ import * as toBeClickable from './matchers/element/toBeClickable.js';
7
+ import * as toBeDisabled from './matchers/element/toBeDisabled.js';
8
+ import * as toBeDisplayed from './matchers/element/toBeDisplayed.js';
9
+ import * as toBeDisplayedInViewport from './matchers/element/toBeDisplayedInViewport.js';
10
+ import * as toBeEnabled from './matchers/element/toBeEnabled.js';
11
+ import * as toBeExisting from './matchers/element/toBeExisting.js';
12
+ import * as toBeFocused from './matchers/element/toBeFocused.js';
13
+ import * as toBeSelected from './matchers/element/toBeSelected.js';
14
+ import * as toHaveAttribute from './matchers/element/toHaveAttribute.js';
15
+ import * as toHaveAttributeContaining from './matchers/element/toHaveAttributeContaining.js';
16
+ import * as toHaveChildren from './matchers/element/toHaveChildren.js';
17
+ import * as toHaveClass from './matchers/element/toHaveClass.js';
18
+ import * as toHaveClassContaining from './matchers/element/toHaveClassContaining.js';
19
+ import * as toHaveHref from './matchers/element/toHaveHref.js';
20
+ import * as toHaveHrefContaining from './matchers/element/toHaveHrefContaining.js';
21
+ import * as toHaveId from './matchers/element/toHaveId.js';
22
+ import * as toHaveElementProperty from './matchers/element/toHaveElementProperty.js';
23
+ import * as toHaveText from './matchers/element/toHaveText.js';
24
+ import * as toHaveTextContaining from './matchers/element/toHaveTextContaining.js';
25
+ import * as toHaveValue from './matchers/element/toHaveValue.js';
26
+ import * as toHaveValueContaining from './matchers/element/toHaveValueContaining.js';
27
+ import * as toHaveStyle from './matchers/element/toHaveStyle.js';
28
+ import * as toBeRequested from './matchers/mock/toBeRequested.js';
29
+ import * as toBeRequestedTimes from './matchers/mock/toBeRequestedTimes.js';
30
+ import * as toBeRequestedWith from './matchers/mock/toBeRequestedWith.js';
3
31
  const matchers = {
4
- ...require('./matchers/browser/toHaveTitle'),
5
- ...require('./matchers/browser/toHaveTitleContaining'),
6
- ...require('./matchers/browser/toHaveUrl'),
7
- ...require('./matchers/browser/toHaveUrlContaining'),
8
- ...require('./matchers/elements/toBeElementsArrayOfSize'),
9
- ...require('./matchers/element/toBeClickable'),
10
- ...require('./matchers/element/toBeDisabled'),
11
- ...require('./matchers/element/toBeDisplayed'),
12
- ...require('./matchers/element/toBeDisplayedInViewport'),
13
- ...require('./matchers/element/toBeEnabled'),
14
- ...require('./matchers/element/toBeExisting'),
15
- ...require('./matchers/element/toBeFocused'),
16
- ...require('./matchers/element/toBeSelected'),
17
- ...require('./matchers/element/toHaveAttribute'),
18
- ...require('./matchers/element/toHaveAttributeContaining'),
19
- ...require('./matchers/element/toHaveChildren'),
20
- ...require('./matchers/element/toHaveElementClass'),
21
- ...require('./matchers/element/toHaveElementClassContaining'),
22
- ...require('./matchers/element/toHaveHref'),
23
- ...require('./matchers/element/toHaveHrefContaining'),
24
- ...require('./matchers/element/toHaveId'),
25
- ...require('./matchers/element/toHaveElementProperty'),
26
- ...require('./matchers/element/toHaveText'),
27
- ...require('./matchers/element/toHaveTextContaining'),
28
- ...require('./matchers/element/toHaveValue'),
29
- ...require('./matchers/element/toHaveValueContaining'),
30
- ...require('./matchers/element/toHaveStyle'),
31
- ...require('./matchers/mock/toBeRequested'),
32
- ...require('./matchers/mock/toBeRequestedTimes'),
33
- ...require('./matchers/mock/toBeRequestedWith'),
34
- ...require('./matchers/mock/toBeRequestedWithResponse'),
32
+ ...toHaveTitle,
33
+ ...toHaveTitleContaining,
34
+ ...toHaveUrl,
35
+ ...toHaveUrlContaining,
36
+ ...toBeElementsArrayOfSize,
37
+ ...toBeClickable,
38
+ ...toBeDisabled,
39
+ ...toBeDisplayed,
40
+ ...toBeDisplayedInViewport,
41
+ ...toBeEnabled,
42
+ ...toBeExisting,
43
+ ...toBeFocused,
44
+ ...toBeSelected,
45
+ ...toHaveAttribute,
46
+ ...toHaveAttributeContaining,
47
+ ...toHaveChildren,
48
+ ...toHaveClass,
49
+ ...toHaveClassContaining,
50
+ ...toHaveHref,
51
+ ...toHaveHrefContaining,
52
+ ...toHaveId,
53
+ ...toHaveElementProperty,
54
+ ...toHaveText,
55
+ ...toHaveTextContaining,
56
+ ...toHaveValue,
57
+ ...toHaveValueContaining,
58
+ ...toHaveStyle,
59
+ ...toBeRequested,
60
+ ...toBeRequestedTimes,
61
+ ...toBeRequestedWith,
35
62
  };
36
- Object.keys(matchers).forEach(key => {
63
+ Object.keys(matchers).forEach((key) => {
37
64
  if (key.endsWith('Fn')) {
38
65
  delete matchers[key];
39
66
  }
40
67
  });
41
- exports.default = matchers;
68
+ export default matchers;
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};