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
@@ -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,51 +1,39 @@
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 { waitUntil, enhanceError, compareNumbers, numberError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
6
2
  async function condition(el, options) {
7
3
  const children = await el.$$('./*');
8
- if (!options.lte && !options.gte && !options.eq) {
4
+ if (typeof options.lte !== 'number' &&
5
+ typeof options.gte !== 'number' &&
6
+ typeof options.eq !== 'number') {
9
7
  return {
10
8
  result: children.length > 0,
11
- value: children === null || children === void 0 ? void 0 : children.length
9
+ value: children?.length
12
10
  };
13
11
  }
14
12
  return {
15
- result: utils_1.compareNumbers(children === null || children === void 0 ? void 0 : children.length, options),
16
- value: children === null || children === void 0 ? void 0 : children.length
13
+ result: compareNumbers(children?.length, options),
14
+ value: children?.length
17
15
  };
18
16
  }
19
- function toHaveChildrenFn(received, expected, options = {}) {
17
+ export async function toHaveChildren(received, expected, options = {}) {
20
18
  const isNot = this.isNot;
21
19
  const { expectation = 'children', verb = 'have' } = this;
22
- let numberOptions;
23
- if (typeof expected === 'number') {
24
- numberOptions = { eq: expected };
25
- }
26
- else if (typeof expected === 'object') {
27
- numberOptions = expected;
28
- }
29
- return browser.call(async () => {
30
- let el = await received;
31
- let children;
32
- const pass = await utils_1.waitUntil(async () => {
33
- const result = await utils_1.executeCommand.call(this, el, condition, numberOptions, [numberOptions]);
34
- el = result.el;
35
- children = result.values;
36
- return result.success;
37
- }, isNot, { ...numberOptions, ...options });
38
- utils_1.updateElementsArray(pass, received, el);
39
- const error = utils_1.numberError(numberOptions);
40
- const expected = utils_1.wrapExpectedWithArray(el, children, error);
41
- const message = utils_1.enhanceError(el, expected, children, this, verb, expectation, '', numberOptions);
42
- return {
43
- pass,
44
- message: () => message
45
- };
46
- });
47
- }
48
- function toHaveChildren(...args) {
49
- return expectAdapter_1.runExpect.call(this, toHaveChildrenFn, args);
20
+ const numberOptions = typeof expected === 'number'
21
+ ? { eq: expected }
22
+ : expected || {};
23
+ let el = await received;
24
+ let children;
25
+ const pass = await waitUntil(async () => {
26
+ const result = await executeCommand.call(this, el, condition, numberOptions, [numberOptions]);
27
+ el = result.el;
28
+ children = result.values;
29
+ return result.success;
30
+ }, isNot, { ...numberOptions, ...options });
31
+ updateElementsArray(pass, received, el);
32
+ const error = numberError(numberOptions);
33
+ const expectedArray = wrapExpectedWithArray(el, children, error);
34
+ const message = enhanceError(el, expectedArray, children, this, verb, expectation, '', numberOptions);
35
+ return {
36
+ pass,
37
+ message: () => message
38
+ };
50
39
  }
51
- exports.toHaveChildren = toHaveChildren;
@@ -0,0 +1,47 @@
1
+ import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
2
+ async function condition(el, attribute, value, options) {
3
+ const { ignoreCase = false, trim = false, containing = false } = options;
4
+ let attr = await el.getAttribute(attribute);
5
+ if (typeof attr !== 'string') {
6
+ return { result: false };
7
+ }
8
+ if (trim) {
9
+ attr = attr.trim();
10
+ }
11
+ if (ignoreCase) {
12
+ attr = attr.toLowerCase();
13
+ if (!(value instanceof RegExp)) {
14
+ value = value.toLowerCase();
15
+ }
16
+ }
17
+ const classes = attr.split(' ');
18
+ const valueInClasses = classes.some((t) => {
19
+ return value instanceof RegExp ? !!t.match(value) : containing ? t.includes(value) : t === value;
20
+ });
21
+ return {
22
+ value: attr,
23
+ result: valueInClasses
24
+ };
25
+ }
26
+ export function toHaveElementClass(...args) {
27
+ return toHaveClass.call(this || {}, ...args);
28
+ }
29
+ export async function toHaveClass(received, className, options = {}) {
30
+ const isNot = this.isNot;
31
+ const { expectation = 'class', verb = 'have' } = this;
32
+ const attribute = 'class';
33
+ let el = await received;
34
+ let attr;
35
+ const pass = await waitUntil(async () => {
36
+ const result = await executeCommand.call(this, el, condition, options, [attribute, className, options]);
37
+ el = result.el;
38
+ attr = result.values;
39
+ return result.success;
40
+ }, isNot, options);
41
+ updateElementsArray(pass, received, el);
42
+ const message = enhanceError(el, wrapExpectedWithArray(el, attr, className), attr, this, verb, expectation, '', options);
43
+ return {
44
+ pass,
45
+ message: () => message
46
+ };
47
+ }
@@ -0,0 +1,10 @@
1
+ import { toHaveAttributeAndValueFn } from './toHaveAttribute.js';
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,4 @@
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 { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
6
2
  async function condition(el, property, value, options = {}) {
7
3
  const { asString = false } = options;
8
4
  let prop = await el.getProperty(property);
@@ -12,41 +8,34 @@ async function condition(el, property, value, options = {}) {
12
8
  if (value === null) {
13
9
  return { result: true, value: prop };
14
10
  }
15
- if (typeof value !== 'string' || (typeof prop !== 'string' && !asString)) {
11
+ if (!(value instanceof RegExp) && (typeof value !== 'string' || (typeof prop !== 'string' && !asString))) {
16
12
  return { result: prop === value, value: prop };
17
13
  }
18
14
  prop = prop.toString();
19
- return utils_1.compareText(prop, value, options);
15
+ return compareText(prop, value, options);
20
16
  }
21
- function toHaveElementPropertyFn(received, property, value, options = {}) {
17
+ export async function toHaveElementProperty(received, property, value, options = {}) {
22
18
  const isNot = this.isNot;
23
19
  const { expectation = 'property', verb = 'have' } = this;
24
- return browser.call(async () => {
25
- let el = await received;
26
- let prop;
27
- const pass = await utils_1.waitUntil(async () => {
28
- const result = await utils_1.executeCommand.call(this, el, condition, options, [property, value]);
29
- el = result.el;
30
- prop = result.values;
31
- return result.success;
32
- }, isNot, options);
33
- utils_1.updateElementsArray(pass, received, el);
34
- let message;
35
- if (value === undefined) {
36
- message = utils_1.enhanceError(el, !isNot, pass, this, verb, expectation, property, options);
37
- }
38
- else {
39
- const expected = utils_1.wrapExpectedWithArray(el, prop, value);
40
- message = utils_1.enhanceError(el, expected, prop, this, verb, expectation, property, options);
41
- }
42
- return {
43
- pass,
44
- message: () => message,
45
- };
46
- });
47
- }
48
- exports.toHaveElementPropertyFn = toHaveElementPropertyFn;
49
- function toHaveElementProperty(...args) {
50
- return expectAdapter_1.runExpect.call(this, toHaveElementPropertyFn, args);
20
+ let el = await received;
21
+ let prop;
22
+ const pass = await waitUntil(async () => {
23
+ const result = await executeCommand.call(this, el, condition, options, [property, value]);
24
+ el = result.el;
25
+ prop = result.values;
26
+ return result.success;
27
+ }, isNot, options);
28
+ updateElementsArray(pass, received, el);
29
+ let message;
30
+ if (value === undefined) {
31
+ message = enhanceError(el, !isNot, pass, this, verb, expectation, property, options);
32
+ }
33
+ else {
34
+ const expected = wrapExpectedWithArray(el, prop, value);
35
+ message = enhanceError(el, expected, prop, this, verb, expectation, property, options);
36
+ }
37
+ return {
38
+ pass,
39
+ message: () => message,
40
+ };
51
41
  }
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.js';
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.js';
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.js';
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,22 @@
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 { waitUntil, enhanceError, compareStyle, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
6
2
  async function condition(el, style, options) {
7
- return utils_1.compareStyle(el, style, options);
3
+ return compareStyle(el, style, options);
8
4
  }
9
- function toHaveStyleFn(received, style, options = {}) {
5
+ export async function toHaveStyle(received, style, options = {}) {
10
6
  const isNot = this.isNot;
11
7
  const { expectation = 'style', verb = 'have' } = this;
12
- return browser.call(async () => {
13
- let el = await received;
14
- let actualStyle;
15
- const pass = await utils_1.waitUntil(async () => {
16
- const result = await utils_1.executeCommand.call(this, el, condition, options, [style, options]);
17
- el = result.el;
18
- actualStyle = result.values;
19
- return result.success;
20
- }, isNot, options);
21
- utils_1.updateElementsArray(pass, received, el);
22
- const message = utils_1.enhanceError(el, utils_1.wrapExpectedWithArray(el, actualStyle, style), actualStyle, this, verb, expectation, '', options);
23
- return {
24
- pass,
25
- message: () => message
26
- };
27
- });
8
+ let el = await received;
9
+ let actualStyle;
10
+ const pass = await waitUntil(async () => {
11
+ const result = await executeCommand.call(this, el, condition, options, [style, options]);
12
+ el = result.el;
13
+ actualStyle = result.values;
14
+ return result.success;
15
+ }, isNot, options);
16
+ updateElementsArray(pass, received, el);
17
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualStyle, style), actualStyle, this, verb, expectation, '', options);
18
+ return {
19
+ pass,
20
+ message: () => message
21
+ };
28
22
  }
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,26 @@
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 { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
6
2
  async function condition(el, text, options) {
7
3
  const actualText = await el.getText();
8
4
  if (Array.isArray(text)) {
9
- return utils_1.compareTextWithArray(actualText, text, options);
5
+ return compareTextWithArray(actualText, text, options);
10
6
  }
11
- return utils_1.compareText(actualText, text, options);
7
+ return compareText(actualText, text, options);
12
8
  }
13
- function toHaveTextFn(received, text, options = {}) {
9
+ export async function toHaveText(received, text, options = {}) {
14
10
  const isNot = this.isNot;
15
11
  const { expectation = 'text', verb = 'have' } = this;
16
- return browser.call(async () => {
17
- let el = await received;
18
- let actualText;
19
- const pass = await utils_1.waitUntil(async () => {
20
- const result = await utils_1.executeCommand.call(this, el, condition, options, [text, options]);
21
- el = result.el;
22
- actualText = result.values;
23
- return result.success;
24
- }, isNot, options);
25
- utils_1.updateElementsArray(pass, received, el);
26
- const message = utils_1.enhanceError(el, utils_1.wrapExpectedWithArray(el, actualText, text), actualText, this, verb, expectation, '', options);
27
- return {
28
- pass,
29
- message: () => message
30
- };
31
- });
12
+ let el = await received;
13
+ let actualText;
14
+ const pass = await waitUntil(async () => {
15
+ const result = await executeCommand.call(this, el, condition, options, [text, options]);
16
+ el = result.el;
17
+ actualText = result.values;
18
+ return result.success;
19
+ }, isNot, options);
20
+ updateElementsArray(pass, received, el);
21
+ const message = enhanceError(el, wrapExpectedWithArray(el, actualText, text), actualText, this, verb, expectation, '', options);
22
+ return {
23
+ pass,
24
+ message: () => message
25
+ };
32
26
  }
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.js';
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.js';
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.js';
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,6 @@
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 { waitUntil, enhanceError, compareNumbers, numberError, updateElementsArray } from '../../utils.js';
2
+ import { refetchElements } from '../../util/refetchElements.js';
3
+ export async function toBeElementsArrayOfSize(received, expected, options = {}) {
8
4
  const isNot = this.isNot;
9
5
  const { expectation = 'elements array of size', verb = 'be' } = this;
10
6
  let numberOptions;
@@ -17,23 +13,17 @@ function toBeElementsArrayOfSizeFn(received, expected, options = {}) {
17
13
  else {
18
14
  numberOptions = expected;
19
15
  }
20
- return browser.call(async () => {
21
- let elements = await received;
22
- const arrLength = elements.length;
23
- const pass = await utils_1.waitUntil(async () => {
24
- elements = await refetchElements_1.refetchElements(elements, numberOptions.wait, true);
25
- return utils_1.compareNumbers(elements.length, numberOptions);
26
- }, isNot, { ...numberOptions, ...options });
27
- utils_1.updateElementsArray(pass, received, elements, true);
28
- const error = utils_1.numberError(numberOptions);
29
- const message = utils_1.enhanceError(elements, error, arrLength, this, verb, expectation, '', numberOptions);
30
- return {
31
- pass,
32
- message: () => message
33
- };
34
- });
16
+ let elements = await received;
17
+ const arrLength = elements.length;
18
+ const pass = await waitUntil(async () => {
19
+ elements = await refetchElements(elements, numberOptions.wait, true);
20
+ return compareNumbers(elements.length, numberOptions);
21
+ }, isNot, { ...numberOptions, ...options });
22
+ updateElementsArray(pass, received, elements, true);
23
+ const error = numberError(numberOptions);
24
+ const message = enhanceError(elements, error, arrLength, this, verb, expectation, '', numberOptions);
25
+ return {
26
+ pass,
27
+ message: () => message
28
+ };
35
29
  }
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.js';
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,35 +1,20 @@
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 { waitUntil, enhanceError, compareNumbers } from '../../utils.js';
2
+ import { numberError } from '../../util/formatMessage.js';
3
+ export async function toBeRequestedTimes(received, expected = {}, options = {}) {
8
4
  const isNot = this.isNot || false;
9
5
  const { expectation = `called${typeof expected === 'number' ? ' ' + expected : ''} time${expected !== 1 ? 's' : ''}`, verb = 'be' } = this;
10
- let numberOptions;
11
- if (typeof expected === 'number') {
12
- numberOptions = { eq: expected };
13
- }
14
- else if (typeof expected === 'object') {
15
- numberOptions = expected;
16
- }
17
- return browser.call(async () => {
18
- let actual;
19
- const pass = await utils_1.waitUntil(async () => {
20
- actual = received.calls.length;
21
- return utils_1.compareNumbers(actual, numberOptions);
22
- }, isNot, { ...numberOptions, ...options });
23
- const error = formatMessage_1.numberError(numberOptions);
24
- const message = utils_1.enhanceError('mock', error, actual, this, verb, expectation, '', numberOptions);
25
- return {
26
- pass,
27
- message: () => message
28
- };
29
- });
6
+ const numberOptions = typeof expected === 'number'
7
+ ? { eq: expected }
8
+ : expected || {};
9
+ let actual;
10
+ const pass = await waitUntil(async () => {
11
+ actual = received.calls.length;
12
+ return compareNumbers(actual, numberOptions);
13
+ }, isNot, { ...numberOptions, ...options });
14
+ const error = numberError(numberOptions);
15
+ const message = enhanceError('mock', error, actual, this, verb, expectation, '', numberOptions);
16
+ return {
17
+ pass,
18
+ message: () => message
19
+ };
30
20
  }
31
- exports.toBeRequestedTimesFn = toBeRequestedTimesFn;
32
- function toBeRequestedTimes(...args) {
33
- return expectAdapter_1.runExpect.call(this, toBeRequestedTimesFn, args);
34
- }
35
- exports.toBeRequestedTimes = toBeRequestedTimes;