expect-webdriverio 4.0.0-alpha.4 → 4.0.0-alpha.6

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.
@@ -1,17 +1,15 @@
1
1
  import { waitUntil, enhanceError, compareText } from '../../utils.js';
2
- export function toHaveTitle(browser, title, options = {}) {
2
+ export async function toHaveTitle(browser, title, options = {}) {
3
3
  const isNot = this.isNot;
4
4
  const { expectation = 'title', verb = 'have' } = this;
5
- return browser.call(async () => {
6
- let actual;
7
- const pass = await waitUntil(async () => {
8
- actual = await browser.getTitle();
9
- return compareText(actual, title, options).result;
10
- }, isNot, options);
11
- const message = enhanceError('window', title, actual, this, verb, expectation, '', options);
12
- return {
13
- pass,
14
- message: () => message
15
- };
16
- });
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
+ };
17
15
  }
@@ -1,17 +1,15 @@
1
1
  import { waitUntil, enhanceError, compareText } from '../../utils.js';
2
- export function toHaveUrl(browser, url, options = {}) {
2
+ export async function toHaveUrl(browser, url, options = {}) {
3
3
  const isNot = this.isNot;
4
4
  const { expectation = 'url', verb = 'have' } = this;
5
- return browser.call(async () => {
6
- let actual;
7
- const pass = await waitUntil(async () => {
8
- actual = await browser.getUrl();
9
- return compareText(actual, url, options).result;
10
- }, isNot, options);
11
- const message = enhanceError('window', url, actual, this, verb, expectation, '', options);
12
- return {
13
- pass,
14
- message: () => message
15
- };
16
- });
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
+ };
17
15
  }
@@ -1,16 +1,12 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommandBe } from '../../utils.js';
3
2
  export function toBeClickable(received, options = {}) {
4
3
  this.expectation = this.expectation || 'clickable';
5
- return browser.call(async () => {
6
- const result = await executeCommandBe.call(this, received, async (el) => {
7
- try {
8
- return el.isClickable();
9
- }
10
- catch {
11
- return false;
12
- }
13
- }, options);
14
- return result;
15
- });
4
+ return executeCommandBe.call(this, received, async (el) => {
5
+ try {
6
+ return el.isClickable();
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ }, options);
16
12
  }
@@ -1,9 +1,5 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommandBe } from '../../utils.js';
3
2
  export function toBeDisabled(received, options = {}) {
4
3
  this.expectation = this.expectation || 'disabled';
5
- return browser.call(async () => {
6
- const result = await executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
7
- return result;
8
- });
4
+ return executeCommandBe.call(this, received, async (el) => !await el.isEnabled(), options);
9
5
  }
@@ -1,16 +1,12 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommandBe } from '../../utils.js';
3
- export function toBeDisplayed(received, options = {}) {
2
+ export async function toBeDisplayed(received, options = {}) {
4
3
  this.expectation = this.expectation || 'displayed';
5
- return browser.call(async () => {
6
- const result = await executeCommandBe.call(this, received, async (el) => {
7
- try {
8
- return el.isDisplayed();
9
- }
10
- catch {
11
- return false;
12
- }
13
- }, options);
14
- return result;
15
- });
4
+ return executeCommandBe.call(this, received, async (el) => {
5
+ try {
6
+ return el.isDisplayed();
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ }, options);
16
12
  }
@@ -1,16 +1,12 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommandBe } from '../../utils.js';
3
2
  export function toBeDisplayedInViewport(received, options = {}) {
4
3
  this.expectation = this.expectation || 'displayed in viewport';
5
- return browser.call(async () => {
6
- const result = await executeCommandBe.call(this, received, async (el) => {
7
- try {
8
- return el.isDisplayedInViewport();
9
- }
10
- catch {
11
- return false;
12
- }
13
- }, options);
14
- return result;
15
- });
4
+ return executeCommandBe.call(this, received, async (el) => {
5
+ try {
6
+ return el.isDisplayedInViewport();
7
+ }
8
+ catch {
9
+ return false;
10
+ }
11
+ }, options);
16
12
  }
@@ -1,9 +1,5 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommandBe } from '../../utils.js';
3
2
  export function toBeEnabled(received, options = {}) {
4
3
  this.expectation = this.expectation || 'enabled';
5
- return browser.call(async () => {
6
- const result = await executeCommandBe.call(this, received, el => el.isEnabled(), options);
7
- return result;
8
- });
4
+ return executeCommandBe.call(this, received, el => el.isEnabled(), options);
9
5
  }
@@ -1,19 +1,15 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommandBe, aliasFn } from '../../utils.js';
3
2
  export function toExist(received, options = {}) {
4
3
  this.expectation = this.expectation || 'exist';
5
4
  this.verb = this.verb || '';
6
- return browser.call(async () => {
7
- const result = await executeCommandBe.call(this, received, async (el) => {
8
- try {
9
- return el.isExisting();
10
- }
11
- catch {
12
- return false;
13
- }
14
- }, options);
15
- return result;
16
- });
5
+ return executeCommandBe.call(this, received, async (el) => {
6
+ try {
7
+ return el.isExisting();
8
+ }
9
+ catch {
10
+ return false;
11
+ }
12
+ }, options);
17
13
  }
18
14
  export function toBeExisting(el, options) {
19
15
  return aliasFn.call(this, toExist, { verb: 'be', expectation: 'existing' }, el, options);
@@ -1,9 +1,5 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommandBe } from '../../utils.js';
3
2
  export function toBeFocused(received, options = {}) {
4
3
  this.expectation = this.expectation || 'focused';
5
- return browser.call(async () => {
6
- const result = await executeCommandBe.call(this, received, el => el.isFocused(), options);
7
- return result;
8
- });
4
+ return executeCommandBe.call(this, received, el => el.isFocused(), options);
9
5
  }
@@ -1,11 +1,7 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommandBe } from '../../utils.js';
3
2
  export function toBeSelected(received, options = {}) {
4
3
  this.expectation = this.expectation || 'selected';
5
- return browser.call(async () => {
6
- const result = await executeCommandBe.call(this, received, el => el.isSelected(), options);
7
- return result;
8
- });
4
+ return executeCommandBe.call(this, received, el => el.isSelected(), options);
9
5
  }
10
6
  export function toBeChecked(el, options) {
11
7
  this.expectation = 'checked';
@@ -1,4 +1,3 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
3
2
  async function conditionAttr(el, attribute) {
4
3
  const attr = await el.getAttribute(attribute);
@@ -16,44 +15,40 @@ async function conditionAttrAndValue(el, attribute, value, options) {
16
15
  }
17
16
  return compareText(attr, value, options);
18
17
  }
19
- export function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
18
+ export async function toHaveAttributeAndValueFn(received, attribute, value, options = {}) {
20
19
  const isNot = this.isNot;
21
20
  const { expectation = 'attribute', verb = 'have' } = this;
22
- return browser.call(async () => {
23
- let el = await received;
24
- let attr;
25
- const pass = await waitUntil(async () => {
26
- const result = await executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options]);
27
- el = result.el;
28
- attr = result.values;
29
- return result.success;
30
- }, isNot, 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);
34
- return {
35
- pass,
36
- message: () => message
37
- };
38
- });
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
+ };
39
36
  }
40
- export function toHaveAttributeFn(received, attribute) {
37
+ export async function toHaveAttributeFn(received, attribute) {
41
38
  const isNot = this.isNot;
42
39
  const { expectation = 'attribute', verb = 'have' } = this;
43
- return browser.call(async () => {
44
- let el = await received;
45
- const pass = await waitUntil(async () => {
46
- const result = await executeCommand.call(this, el, conditionAttr, {}, [attribute]);
47
- el = result.el;
48
- return result.success;
49
- }, isNot, {});
50
- updateElementsArray(pass, received, el);
51
- const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {});
52
- return {
53
- pass,
54
- message: () => message
55
- };
56
- });
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
+ };
57
52
  }
58
53
  export function toHaveAttribute(...args) {
59
54
  if (args.length === 3 || args.length === 4) {
@@ -1,4 +1,3 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError, compareNumbers, numberError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
3
2
  async function condition(el, options) {
4
3
  const children = await el.$$('./*');
@@ -15,32 +14,26 @@ async function condition(el, options) {
15
14
  value: children?.length
16
15
  };
17
16
  }
18
- export function toHaveChildren(received, expected, options = {}) {
17
+ export async function toHaveChildren(received, expected, options = {}) {
19
18
  const isNot = this.isNot;
20
19
  const { expectation = 'children', verb = 'have' } = this;
21
- let numberOptions;
22
- if (typeof expected === 'number') {
23
- numberOptions = { eq: expected };
24
- }
25
- else if (typeof expected === 'object') {
26
- numberOptions = expected;
27
- }
28
- return browser.call(async () => {
29
- let el = await received;
30
- let children;
31
- const pass = await waitUntil(async () => {
32
- const result = await executeCommand.call(this, el, condition, numberOptions, [numberOptions]);
33
- el = result.el;
34
- children = result.values;
35
- return result.success;
36
- }, isNot, { ...numberOptions, ...options });
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);
41
- return {
42
- pass,
43
- message: () => message
44
- };
45
- });
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
+ };
46
39
  }
@@ -1,4 +1,3 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
3
2
  async function condition(el, attribute, value, options) {
4
3
  const { ignoreCase = false, trim = false, containing = false } = options;
@@ -27,24 +26,22 @@ async function condition(el, attribute, value, options) {
27
26
  export function toHaveElementClass(...args) {
28
27
  return toHaveClass.call(this || {}, ...args);
29
28
  }
30
- export function toHaveClass(received, className, options = {}) {
29
+ export async function toHaveClass(received, className, options = {}) {
31
30
  const isNot = this.isNot;
32
31
  const { expectation = 'class', verb = 'have' } = this;
33
32
  const attribute = 'class';
34
- return browser.call(async () => {
35
- let el = await received;
36
- let attr;
37
- const pass = await waitUntil(async () => {
38
- const result = await executeCommand.call(this, el, condition, options, [attribute, className, options]);
39
- el = result.el;
40
- attr = result.values;
41
- return result.success;
42
- }, isNot, options);
43
- updateElementsArray(pass, received, el);
44
- const message = enhanceError(el, wrapExpectedWithArray(el, attr, className), attr, this, verb, expectation, '', options);
45
- return {
46
- pass,
47
- message: () => message
48
- };
49
- });
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
+ };
50
47
  }
@@ -1,4 +1,3 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
3
2
  async function condition(el, property, value, options = {}) {
4
3
  const { asString = false } = options;
@@ -15,30 +14,28 @@ async function condition(el, property, value, options = {}) {
15
14
  prop = prop.toString();
16
15
  return compareText(prop, value, options);
17
16
  }
18
- export function toHaveElementProperty(received, property, value, options = {}) {
17
+ export async function toHaveElementProperty(received, property, value, options = {}) {
19
18
  const isNot = this.isNot;
20
19
  const { expectation = 'property', verb = 'have' } = this;
21
- return browser.call(async () => {
22
- let el = await received;
23
- let prop;
24
- const pass = await waitUntil(async () => {
25
- const result = await executeCommand.call(this, el, condition, options, [property, value]);
26
- el = result.el;
27
- prop = result.values;
28
- return result.success;
29
- }, isNot, options);
30
- updateElementsArray(pass, received, el);
31
- let message;
32
- if (value === undefined) {
33
- message = enhanceError(el, !isNot, pass, this, verb, expectation, property, options);
34
- }
35
- else {
36
- const expected = wrapExpectedWithArray(el, prop, value);
37
- message = enhanceError(el, expected, prop, this, verb, expectation, property, options);
38
- }
39
- return {
40
- pass,
41
- message: () => message,
42
- };
43
- });
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
+ };
44
41
  }
@@ -1,25 +1,22 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError, compareStyle, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
3
2
  async function condition(el, style, options) {
4
3
  return compareStyle(el, style, options);
5
4
  }
6
- export function toHaveStyle(received, style, options = {}) {
5
+ export async function toHaveStyle(received, style, options = {}) {
7
6
  const isNot = this.isNot;
8
7
  const { expectation = 'style', verb = 'have' } = this;
9
- return browser.call(async () => {
10
- let el = await received;
11
- let actualStyle;
12
- const pass = await waitUntil(async () => {
13
- const result = await executeCommand.call(this, el, condition, options, [style, options]);
14
- el = result.el;
15
- actualStyle = result.values;
16
- return result.success;
17
- }, isNot, options);
18
- updateElementsArray(pass, received, el);
19
- const message = enhanceError(el, wrapExpectedWithArray(el, actualStyle, style), actualStyle, this, verb, expectation, '', options);
20
- return {
21
- pass,
22
- message: () => message
23
- };
24
- });
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
+ };
25
22
  }
@@ -1,4 +1,3 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
3
2
  async function condition(el, text, options) {
4
3
  const actualText = await el.getText();
@@ -7,23 +6,21 @@ async function condition(el, text, options) {
7
6
  }
8
7
  return compareText(actualText, text, options);
9
8
  }
10
- export function toHaveText(received, text, options = {}) {
9
+ export async function toHaveText(received, text, options = {}) {
11
10
  const isNot = this.isNot;
12
11
  const { expectation = 'text', verb = 'have' } = this;
13
- return browser.call(async () => {
14
- let el = await received;
15
- let actualText;
16
- const pass = await waitUntil(async () => {
17
- const result = await executeCommand.call(this, el, condition, options, [text, options]);
18
- el = result.el;
19
- actualText = result.values;
20
- return result.success;
21
- }, isNot, options);
22
- updateElementsArray(pass, received, el);
23
- const message = enhanceError(el, wrapExpectedWithArray(el, actualText, text), actualText, this, verb, expectation, '', options);
24
- return {
25
- pass,
26
- message: () => message
27
- };
28
- });
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
+ };
29
26
  }
@@ -1,7 +1,6 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError, compareNumbers, numberError, updateElementsArray } from '../../utils.js';
3
2
  import { refetchElements } from '../../util/refetchElements.js';
4
- export function toBeElementsArrayOfSize(received, expected, options = {}) {
3
+ export async function toBeElementsArrayOfSize(received, expected, options = {}) {
5
4
  const isNot = this.isNot;
6
5
  const { expectation = 'elements array of size', verb = 'be' } = this;
7
6
  let numberOptions;
@@ -14,19 +13,17 @@ export function toBeElementsArrayOfSize(received, expected, options = {}) {
14
13
  else {
15
14
  numberOptions = expected;
16
15
  }
17
- return browser.call(async () => {
18
- let elements = await received;
19
- const arrLength = elements.length;
20
- const pass = await waitUntil(async () => {
21
- elements = await refetchElements(elements, numberOptions.wait, true);
22
- return compareNumbers(elements.length, numberOptions);
23
- }, isNot, { ...numberOptions, ...options });
24
- updateElementsArray(pass, received, elements, true);
25
- const error = numberError(numberOptions);
26
- const message = enhanceError(elements, error, arrLength, this, verb, expectation, '', numberOptions);
27
- return {
28
- pass,
29
- message: () => message
30
- };
31
- });
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
+ };
32
29
  }
@@ -1,27 +1,20 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError, compareNumbers } from '../../utils.js';
3
2
  import { numberError } from '../../util/formatMessage.js';
4
- export function toBeRequestedTimes(received, expected = {}, options = {}) {
3
+ export async function toBeRequestedTimes(received, expected = {}, options = {}) {
5
4
  const isNot = this.isNot || false;
6
5
  const { expectation = `called${typeof expected === 'number' ? ' ' + expected : ''} time${expected !== 1 ? 's' : ''}`, verb = 'be' } = this;
7
- let numberOptions;
8
- if (typeof expected === 'number') {
9
- numberOptions = { eq: expected };
10
- }
11
- else if (typeof expected === 'object') {
12
- numberOptions = expected;
13
- }
14
- return browser.call(async () => {
15
- let actual;
16
- const pass = await waitUntil(async () => {
17
- actual = received.calls.length;
18
- return compareNumbers(actual, numberOptions);
19
- }, isNot, { ...numberOptions, ...options });
20
- const error = numberError(numberOptions);
21
- const message = enhanceError('mock', error, actual, this, verb, expectation, '', numberOptions);
22
- return {
23
- pass,
24
- message: () => message
25
- };
26
- });
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
+ };
27
20
  }
@@ -1,34 +1,31 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { waitUntil, enhanceError } from '../../utils.js';
3
2
  import { equals } from '../../jasmineUtils.js';
4
3
  const STR_LIMIT = 80;
5
4
  const KEY_LIMIT = 12;
6
- export function toBeRequestedWith(received, requestedWith = {}, options = {}) {
5
+ export async function toBeRequestedWith(received, requestedWith = {}, options = {}) {
7
6
  const isNot = this.isNot || false;
8
7
  const { expectation = 'called with', verb = 'be' } = this;
9
- return browser.call(async () => {
10
- let actual;
11
- const pass = await waitUntil(async () => {
12
- for (const call of received.calls) {
13
- actual = call;
14
- if (methodMatcher(call.method, requestedWith.method) &&
15
- statusCodeMatcher(call.statusCode, requestedWith.statusCode) &&
16
- urlMatcher(call.url, requestedWith.url) &&
17
- headersMatcher(call.headers, requestedWith.requestHeaders) &&
18
- headersMatcher(call.responseHeaders, requestedWith.responseHeaders) &&
19
- bodyMatcher(call.postData, requestedWith.postData) &&
20
- bodyMatcher(call.body, requestedWith.response)) {
21
- return true;
22
- }
8
+ let actual;
9
+ const pass = await waitUntil(async () => {
10
+ for (const call of received.calls) {
11
+ actual = call;
12
+ if (methodMatcher(call.method, requestedWith.method) &&
13
+ statusCodeMatcher(call.statusCode, requestedWith.statusCode) &&
14
+ urlMatcher(call.url, requestedWith.url) &&
15
+ headersMatcher(call.headers, requestedWith.requestHeaders) &&
16
+ headersMatcher(call.responseHeaders, requestedWith.responseHeaders) &&
17
+ bodyMatcher(call.postData, requestedWith.postData) &&
18
+ bodyMatcher(call.body, requestedWith.response)) {
19
+ return true;
23
20
  }
24
- return false;
25
- }, isNot, { ...options, wait: isNot ? 0 : options.wait });
26
- const message = enhanceError('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
27
- return {
28
- pass,
29
- message: () => message,
30
- };
31
- });
21
+ }
22
+ return false;
23
+ }, isNot, { ...options, wait: isNot ? 0 : options.wait });
24
+ const message = enhanceError('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
25
+ return {
26
+ pass,
27
+ message: () => message,
28
+ };
32
29
  }
33
30
  const methodMatcher = (method, expected) => {
34
31
  if (typeof expected === 'undefined') {
package/lib/utils.js CHANGED
@@ -1,27 +1,32 @@
1
- import { browser } from '@wdio/globals';
2
1
  import { executeCommand } from './util/executeCommand.js';
3
2
  import { wrapExpectedWithArray, updateElementsArray } from './util/elementsUtil.js';
4
3
  import { enhanceError, enhanceErrorBe, numberError } from './util/formatMessage.js';
5
4
  import { DEFAULT_OPTIONS } from './constants.js';
5
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
6
6
  const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait, interval = DEFAULT_OPTIONS.interval } = {}) => {
7
7
  if (wait === 0) {
8
8
  return await condition();
9
9
  }
10
10
  try {
11
11
  let error;
12
- await browser.waitUntil(async () => {
12
+ const start = Date.now();
13
+ while (true) {
14
+ if ((Date.now() - start) > wait) {
15
+ throw new Error('timeout');
16
+ }
13
17
  error = undefined;
14
18
  try {
15
- return isNot !== await condition();
19
+ const result = isNot !== await condition();
20
+ if (result) {
21
+ break;
22
+ }
23
+ await sleep(interval);
16
24
  }
17
25
  catch (err) {
18
26
  error = err;
19
- return false;
27
+ await sleep(interval);
20
28
  }
21
- }, {
22
- timeout: wait,
23
- interval
24
- });
29
+ }
25
30
  if (error) {
26
31
  throw error;
27
32
  }
@@ -145,4 +150,4 @@ function aliasFn(fn, { verb, expectation } = {}, ...args) {
145
150
  this.expectation = expectation;
146
151
  return fn.apply(this, args);
147
152
  }
148
- export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn, };
153
+ export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "4.0.0-alpha.4",
3
+ "version": "4.0.0-alpha.6",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -48,6 +48,7 @@
48
48
  "@typescript-eslint/eslint-plugin": "^5.33.0",
49
49
  "@typescript-eslint/parser": "^5.33.0",
50
50
  "@vitest/coverage-c8": "^0.24.0",
51
+ "@wdio/globals": "^8.0.0-alpha.505",
51
52
  "c8": "^7.12.0",
52
53
  "eslint": "^8.21.0",
53
54
  "eslint-plugin-import": "^2.26.0",
@@ -58,19 +59,12 @@
58
59
  "rimraf": "^3.0.2",
59
60
  "shelljs": "^0.8.5",
60
61
  "typescript": "^4.7.4",
61
- "vitest": "0.24.3"
62
+ "vitest": "0.24.4",
63
+ "webdriverio": "^8.0.0-alpha.505"
62
64
  },
63
- "peerDependencies": {
64
- "@wdio/globals": "^8.0.0-alpha.365",
65
- "webdriverio": "^8.0.0-alpha.365"
66
- },
67
- "peerDependenciesMeta": {
68
- "@wdio/globals": {
69
- "optional": false
70
- },
71
- "webdriverio": {
72
- "optional": false
73
- }
65
+ "optionalDependencies": {
66
+ "@wdio/globals": "^8.0.0-alpha.505",
67
+ "webdriverio": "^8.0.0-alpha.505"
74
68
  },
75
69
  "dependencies": {
76
70
  "expect": "^29.0.2",