expect-webdriverio 4.6.0 → 4.7.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 (38) hide show
  1. package/lib/index.js +2 -1
  2. package/lib/matchers/browser/toHaveClipboardText.js +3 -2
  3. package/lib/matchers/browser/toHaveTitle.js +2 -1
  4. package/lib/matchers/browser/toHaveUrl.js +3 -2
  5. package/lib/matchers/element/toBeClickable.js +2 -1
  6. package/lib/matchers/element/toBeDisabled.js +2 -1
  7. package/lib/matchers/element/toBeDisplayed.js +2 -1
  8. package/lib/matchers/element/toBeDisplayedInViewport.js +2 -1
  9. package/lib/matchers/element/toBeEnabled.js +2 -1
  10. package/lib/matchers/element/toBeExisting.js +2 -1
  11. package/lib/matchers/element/toBeFocused.js +2 -1
  12. package/lib/matchers/element/toBeSelected.js +3 -2
  13. package/lib/matchers/element/toHaveAttribute.js +4 -3
  14. package/lib/matchers/element/toHaveChildren.js +2 -1
  15. package/lib/matchers/element/toHaveClass.js +3 -2
  16. package/lib/matchers/element/toHaveComputedLabel.js +3 -2
  17. package/lib/matchers/element/toHaveComputedRole.js +3 -2
  18. package/lib/matchers/element/toHaveElementProperty.js +3 -2
  19. package/lib/matchers/element/toHaveHTML.js +3 -2
  20. package/lib/matchers/element/toHaveHeight.js +2 -1
  21. package/lib/matchers/element/toHaveHref.js +3 -2
  22. package/lib/matchers/element/toHaveId.js +2 -1
  23. package/lib/matchers/element/toHaveSize.js +2 -1
  24. package/lib/matchers/element/toHaveStyle.js +2 -1
  25. package/lib/matchers/element/toHaveText.js +3 -2
  26. package/lib/matchers/element/toHaveValue.js +3 -2
  27. package/lib/matchers/element/toHaveWidth.js +2 -1
  28. package/lib/matchers/element/toMatchElementSnapshot.js +9 -0
  29. package/lib/matchers/elements/toBeElementsArrayOfSize.js +2 -1
  30. package/lib/matchers/general/toMatchSnapshot.js +9 -0
  31. package/lib/matchers/mock/toBeRequested.js +2 -1
  32. package/lib/matchers/mock/toBeRequestedTimes.js +2 -1
  33. package/lib/matchers/mock/toBeRequestedWith.js +2 -1
  34. package/lib/matchers.js +4 -0
  35. package/package.json +4 -3
  36. package/types/expect-webdriverio.d.ts +38 -17
  37. package/types/jest-global.d.ts +0 -2
  38. package/types/standalone.d.ts +2 -2
package/lib/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { expect as expectLib } from 'expect';
1
+ import { jestExpect as expectLib } from '@jest/expect';
2
2
  import wdioMatchers from './matchers.js';
3
3
  import * as expectUtils from './utils.js';
4
4
  import { DEFAULT_OPTIONS } from './constants.js';
5
+ expectLib.setState({ suppressedErrors: [] });
5
6
  expectLib.extend({ ...wdioMatchers });
6
7
  export const expect = expectLib;
7
8
  export const matchers = wdioMatchers;
@@ -1,7 +1,8 @@
1
- import { waitUntil, enhanceError, compareText } from '../../utils.js';
2
1
  import logger from '@wdio/logger';
2
+ import { waitUntil, enhanceError, compareText } from '../../utils.js';
3
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
4
  const log = logger('expect-webdriverio');
4
- export async function toHaveClipboardText(browser, expectedValue, options = {}) {
5
+ export async function toHaveClipboardText(browser, expectedValue, options = DEFAULT_OPTIONS) {
5
6
  const isNot = this.isNot;
6
7
  const { expectation = 'clipboard text', verb = 'have' } = this;
7
8
  await options.beforeAssertion?.({
@@ -1,5 +1,6 @@
1
1
  import { waitUntil, enhanceError, compareText } from '../../utils.js';
2
- export async function toHaveTitle(browser, expectedValue, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toHaveTitle(browser, expectedValue, options = DEFAULT_OPTIONS) {
3
4
  const isNot = this.isNot;
4
5
  const { expectation = 'title', verb = 'have' } = this;
5
6
  await options.beforeAssertion?.({
@@ -1,5 +1,6 @@
1
1
  import { waitUntil, enhanceError, compareText } from '../../utils.js';
2
- export async function toHaveUrl(browser, expectedValue, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toHaveUrl(browser, expectedValue, options = DEFAULT_OPTIONS) {
3
4
  const isNot = this.isNot;
4
5
  const { expectation = 'url', verb = 'have' } = this;
5
6
  await options.beforeAssertion?.({
@@ -25,7 +26,7 @@ export async function toHaveUrl(browser, expectedValue, options = {}) {
25
26
  });
26
27
  return result;
27
28
  }
28
- export function toHaveUrlContaining(browser, url, options = {}) {
29
+ export function toHaveUrlContaining(browser, url, options = DEFAULT_OPTIONS) {
29
30
  return toHaveUrl.call(this, browser, url, {
30
31
  ...options,
31
32
  containing: true
@@ -1,5 +1,6 @@
1
1
  import { executeCommandBe } from '../../utils.js';
2
- export async function toBeClickable(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toBeClickable(received, options = DEFAULT_OPTIONS) {
3
4
  this.expectation = this.expectation || 'clickable';
4
5
  await options.beforeAssertion?.({
5
6
  matcherName: 'toBeClickable',
@@ -1,5 +1,6 @@
1
1
  import { executeCommandBe } from '../../utils.js';
2
- export async function toBeDisabled(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toBeDisabled(received, options = DEFAULT_OPTIONS) {
3
4
  this.expectation = this.expectation || 'disabled';
4
5
  await options.beforeAssertion?.({
5
6
  matcherName: 'toBeDisabled',
@@ -1,5 +1,6 @@
1
1
  import { executeCommandBe } from '../../utils.js';
2
- export async function toBeDisplayed(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toBeDisplayed(received, options = DEFAULT_OPTIONS) {
3
4
  this.expectation = this.expectation || 'displayed';
4
5
  await options.beforeAssertion?.({
5
6
  matcherName: 'toBeDisplayed',
@@ -1,5 +1,6 @@
1
1
  import { executeCommandBe } from '../../utils.js';
2
- export async function toBeDisplayedInViewport(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toBeDisplayedInViewport(received, options = DEFAULT_OPTIONS) {
3
4
  this.expectation = this.expectation || 'displayed in viewport';
4
5
  await options.beforeAssertion?.({
5
6
  matcherName: 'toBeDisplayedInViewport',
@@ -1,5 +1,6 @@
1
1
  import { executeCommandBe } from '../../utils.js';
2
- export async function toBeEnabled(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toBeEnabled(received, options = DEFAULT_OPTIONS) {
3
4
  this.expectation = this.expectation || 'enabled';
4
5
  await options.beforeAssertion?.({
5
6
  matcherName: 'toBeEnabled',
@@ -1,5 +1,6 @@
1
1
  import { executeCommandBe, aliasFn } from '../../utils.js';
2
- export async function toExist(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toExist(received, options = DEFAULT_OPTIONS) {
3
4
  this.expectation = this.expectation || 'exist';
4
5
  this.verb = this.verb || '';
5
6
  await options.beforeAssertion?.({
@@ -1,5 +1,6 @@
1
1
  import { executeCommandBe } from '../../utils.js';
2
- export async function toBeFocused(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toBeFocused(received, options = DEFAULT_OPTIONS) {
3
4
  this.expectation = this.expectation || 'focused';
4
5
  await options.beforeAssertion?.({
5
6
  matcherName: 'toBeFocused',
@@ -1,5 +1,6 @@
1
1
  import { executeCommandBe } from '../../utils.js';
2
- export async function toBeSelected(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toBeSelected(received, options = DEFAULT_OPTIONS) {
3
4
  this.expectation = this.expectation || 'selected';
4
5
  await options.beforeAssertion?.({
5
6
  matcherName: 'toBeSelected',
@@ -13,7 +14,7 @@ export async function toBeSelected(received, options = {}) {
13
14
  });
14
15
  return result;
15
16
  }
16
- export async function toBeChecked(el, options = {}) {
17
+ export async function toBeChecked(el, options = DEFAULT_OPTIONS) {
17
18
  this.expectation = 'checked';
18
19
  await options.beforeAssertion?.({
19
20
  matcherName: 'toBeChecked',
@@ -1,4 +1,5 @@
1
1
  import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function conditionAttr(el, attribute) {
3
4
  const attr = await el.getAttribute(attribute);
4
5
  if (typeof attr !== 'string') {
@@ -15,7 +16,7 @@ async function conditionAttrAndValue(el, attribute, value, options) {
15
16
  }
16
17
  return compareText(attr, value, options);
17
18
  }
18
- export async function toHaveAttributeAndValue(received, attribute, value, options = {}) {
19
+ export async function toHaveAttributeAndValue(received, attribute, value, options = DEFAULT_OPTIONS) {
19
20
  const isNot = this.isNot;
20
21
  const { expectation = 'attribute', verb = 'have' } = this;
21
22
  let el = await received;
@@ -50,7 +51,7 @@ async function toHaveAttributeFn(received, attribute) {
50
51
  message: () => message
51
52
  };
52
53
  }
53
- export async function toHaveAttribute(received, attribute, value, options = {}) {
54
+ export async function toHaveAttribute(received, attribute, value, options = DEFAULT_OPTIONS) {
54
55
  await options.beforeAssertion?.({
55
56
  matcherName: 'toHaveAttribute',
56
57
  expectedValue: [attribute, value],
@@ -67,7 +68,7 @@ export async function toHaveAttribute(received, attribute, value, options = {})
67
68
  });
68
69
  return result;
69
70
  }
70
- export function toHaveAttributeContaining(el, attribute, value, options = {}) {
71
+ export function toHaveAttributeContaining(el, attribute, value, options = DEFAULT_OPTIONS) {
71
72
  return toHaveAttributeAndValue.call(this, el, attribute, value, {
72
73
  ...options,
73
74
  containing: true
@@ -1,4 +1,5 @@
1
1
  import { waitUntil, enhanceError, compareNumbers, numberError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, options) {
3
4
  const children = await el.$$('./*');
4
5
  if (typeof options.lte !== 'number' &&
@@ -14,7 +15,7 @@ async function condition(el, options) {
14
15
  value: children?.length
15
16
  };
16
17
  }
17
- export async function toHaveChildren(received, expectedValue, options = {}) {
18
+ export async function toHaveChildren(received, expectedValue, options = DEFAULT_OPTIONS) {
18
19
  const isNot = this.isNot;
19
20
  const { expectation = 'children', verb = 'have' } = this;
20
21
  await options.beforeAssertion?.({
@@ -1,5 +1,6 @@
1
1
  import { toHaveAttributeAndValue } from './toHaveAttribute.js';
2
2
  import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, compareText } from '../../utils.js';
3
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
4
  async function condition(el, attribute, value, options) {
4
5
  const { ignoreCase = false, trim = false, containing = false } = options;
5
6
  let attr = await el.getAttribute(attribute);
@@ -31,7 +32,7 @@ async function condition(el, attribute, value, options) {
31
32
  export function toHaveClass(...args) {
32
33
  return toHaveElementClass.call(this || {}, ...args);
33
34
  }
34
- export async function toHaveElementClass(received, expectedValue, options = {}) {
35
+ export async function toHaveElementClass(received, expectedValue, options = DEFAULT_OPTIONS) {
35
36
  const isNot = this.isNot;
36
37
  const { expectation = 'class', verb = 'have' } = this;
37
38
  await options.beforeAssertion?.({
@@ -65,7 +66,7 @@ export async function toHaveElementClass(received, expectedValue, options = {})
65
66
  export function toHaveElementClassContaining(...args) {
66
67
  return toHaveClassContaining.call(this, ...args);
67
68
  }
68
- export function toHaveClassContaining(el, className, options = {}) {
69
+ export function toHaveClassContaining(el, className, options = DEFAULT_OPTIONS) {
69
70
  return toHaveAttributeAndValue.call(this, el, 'class', className, {
70
71
  ...options,
71
72
  containing: true
@@ -1,4 +1,5 @@
1
1
  import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, label, options) {
3
4
  const actualLabel = await el.getComputedLabel();
4
5
  if (Array.isArray(label)) {
@@ -6,7 +7,7 @@ async function condition(el, label, options) {
6
7
  }
7
8
  return compareText(actualLabel, label, options);
8
9
  }
9
- export async function toHaveComputedLabel(received, expectedValue, options = {}) {
10
+ export async function toHaveComputedLabel(received, expectedValue, options = DEFAULT_OPTIONS) {
10
11
  const isNot = this.isNot;
11
12
  const { expectation = 'computed label', verb = 'have' } = this;
12
13
  await options.beforeAssertion?.({
@@ -36,7 +37,7 @@ export async function toHaveComputedLabel(received, expectedValue, options = {})
36
37
  });
37
38
  return result;
38
39
  }
39
- export function toHaveComputedLabelContaining(el, label, options = {}) {
40
+ export function toHaveComputedLabelContaining(el, label, options = DEFAULT_OPTIONS) {
40
41
  return toHaveComputedLabel.call(this, el, label, {
41
42
  ...options,
42
43
  containing: true
@@ -1,4 +1,5 @@
1
1
  import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, role, options) {
3
4
  const actualRole = await el.getComputedRole();
4
5
  if (Array.isArray(role)) {
@@ -6,7 +7,7 @@ async function condition(el, role, options) {
6
7
  }
7
8
  return compareText(actualRole, role, options);
8
9
  }
9
- export async function toHaveComputedRole(received, expectedValue, options = {}) {
10
+ export async function toHaveComputedRole(received, expectedValue, options = DEFAULT_OPTIONS) {
10
11
  const isNot = this.isNot;
11
12
  const { expectation = 'computed role', verb = 'have' } = this;
12
13
  await options.beforeAssertion?.({
@@ -36,7 +37,7 @@ export async function toHaveComputedRole(received, expectedValue, options = {})
36
37
  });
37
38
  return result;
38
39
  }
39
- export function toHaveComputedRoleContaining(el, role, options = {}) {
40
+ export function toHaveComputedRoleContaining(el, role, options = DEFAULT_OPTIONS) {
40
41
  return toHaveComputedRole.call(this, el, role, {
41
42
  ...options,
42
43
  containing: true
@@ -1,5 +1,6 @@
1
1
  import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
- async function condition(el, property, value, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ async function condition(el, property, value, options = DEFAULT_OPTIONS) {
3
4
  const { asString = false } = options;
4
5
  let prop = await el.getProperty(property);
5
6
  if (prop === null || prop === undefined) {
@@ -14,7 +15,7 @@ async function condition(el, property, value, options = {}) {
14
15
  prop = prop.toString();
15
16
  return compareText(prop, value, options);
16
17
  }
17
- export async function toHaveElementProperty(received, property, value, options = {}) {
18
+ export async function toHaveElementProperty(received, property, value, options = DEFAULT_OPTIONS) {
18
19
  const isNot = this.isNot;
19
20
  const { expectation = 'property', verb = 'have' } = this;
20
21
  await options.beforeAssertion?.({
@@ -1,4 +1,5 @@
1
1
  import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, html, options) {
3
4
  const actualHTML = await el.getHTML(options.includeSelectorTag);
4
5
  if (Array.isArray(html)) {
@@ -6,7 +7,7 @@ async function condition(el, html, options) {
6
7
  }
7
8
  return compareText(actualHTML, html, options);
8
9
  }
9
- export async function toHaveHTML(received, expectedValue, options = {}) {
10
+ export async function toHaveHTML(received, expectedValue, options = DEFAULT_OPTIONS) {
10
11
  const isNot = this.isNot;
11
12
  const { expectation = 'HTML', verb = 'have' } = this;
12
13
  await options.beforeAssertion?.({
@@ -36,7 +37,7 @@ export async function toHaveHTML(received, expectedValue, options = {}) {
36
37
  });
37
38
  return result;
38
39
  }
39
- export function toHaveHTMLContaining(el, html, options = {}) {
40
+ export function toHaveHTMLContaining(el, html, options = DEFAULT_OPTIONS) {
40
41
  return toHaveHTML.call(this, el, html, {
41
42
  ...options,
42
43
  containing: true
@@ -1,4 +1,5 @@
1
1
  import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, height) {
3
4
  const actualHeight = await el.getSize('height');
4
5
  return {
@@ -6,7 +7,7 @@ async function condition(el, height) {
6
7
  result: actualHeight === height,
7
8
  };
8
9
  }
9
- export async function toHaveHeight(received, expectedValue, options = {}) {
10
+ export async function toHaveHeight(received, expectedValue, options = DEFAULT_OPTIONS) {
10
11
  const isNot = this.isNot;
11
12
  const { expectation = 'height', verb = 'have' } = this;
12
13
  await options.beforeAssertion?.({
@@ -1,5 +1,6 @@
1
1
  import { toHaveAttributeAndValue } from './toHaveAttribute.js';
2
- export async function toHaveHref(el, expectedValue, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toHaveHref(el, expectedValue, options = DEFAULT_OPTIONS) {
3
4
  await options.beforeAssertion?.({
4
5
  matcherName: 'toHaveHref',
5
6
  expectedValue,
@@ -15,7 +16,7 @@ export async function toHaveHref(el, expectedValue, options = {}) {
15
16
  return result;
16
17
  }
17
18
  export const toHaveLink = toHaveHref;
18
- export function toHaveHrefContaining(el, href, options = {}) {
19
+ export function toHaveHrefContaining(el, href, options = DEFAULT_OPTIONS) {
19
20
  return toHaveHref.call(this, el, href, {
20
21
  ...options,
21
22
  containing: true
@@ -1,5 +1,6 @@
1
1
  import { toHaveAttributeAndValue } from './toHaveAttribute.js';
2
- export async function toHaveId(el, expectedValue, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export async function toHaveId(el, expectedValue, options = DEFAULT_OPTIONS) {
3
4
  await options.beforeAssertion?.({
4
5
  matcherName: 'toHaveId',
5
6
  expectedValue,
@@ -1,9 +1,10 @@
1
1
  import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, compareObject, } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, size) {
3
4
  const actualSize = await el.getSize();
4
5
  return compareObject(actualSize, size);
5
6
  }
6
- export async function toHaveSize(received, expectedValue, options = {}) {
7
+ export async function toHaveSize(received, expectedValue, options = DEFAULT_OPTIONS) {
7
8
  const isNot = this.isNot;
8
9
  const { expectation = 'size', verb = 'have' } = this;
9
10
  await options.beforeAssertion?.({
@@ -1,8 +1,9 @@
1
1
  import { waitUntil, enhanceError, compareStyle, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, style, options) {
3
4
  return compareStyle(el, style, options);
4
5
  }
5
- export async function toHaveStyle(received, expectedValue, options = {}) {
6
+ export async function toHaveStyle(received, expectedValue, options = DEFAULT_OPTIONS) {
6
7
  const isNot = this.isNot;
7
8
  const { expectation = 'style', verb = 'have' } = this;
8
9
  await options.beforeAssertion?.({
@@ -1,4 +1,5 @@
1
1
  import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, text, options) {
3
4
  const actualText = await el.getText();
4
5
  if (Array.isArray(text)) {
@@ -6,7 +7,7 @@ async function condition(el, text, options) {
6
7
  }
7
8
  return compareText(actualText, text, options);
8
9
  }
9
- export async function toHaveText(received, expectedValue, options = {}) {
10
+ export async function toHaveText(received, expectedValue, options = DEFAULT_OPTIONS) {
10
11
  const isNot = this.isNot;
11
12
  const { expectation = 'text', verb = 'have' } = this;
12
13
  await options.beforeAssertion?.({
@@ -36,7 +37,7 @@ export async function toHaveText(received, expectedValue, options = {}) {
36
37
  });
37
38
  return result;
38
39
  }
39
- export function toHaveTextContaining(el, text, options = {}) {
40
+ export function toHaveTextContaining(el, text, options = DEFAULT_OPTIONS) {
40
41
  return toHaveText.call(this, el, text, {
41
42
  ...options,
42
43
  containing: true
@@ -1,8 +1,9 @@
1
1
  import { toHaveElementProperty } from './toHaveElementProperty.js';
2
- export function toHaveValue(el, value, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export function toHaveValue(el, value, options = DEFAULT_OPTIONS) {
3
4
  return toHaveElementProperty.call(this, el, 'value', value, options);
4
5
  }
5
- export function toHaveValueContaining(el, value, options = {}) {
6
+ export function toHaveValueContaining(el, value, options = DEFAULT_OPTIONS) {
6
7
  return toHaveValue.call(this, el, value, {
7
8
  ...options,
8
9
  containing: true
@@ -1,4 +1,5 @@
1
1
  import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, } from '../../utils.js';
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
2
3
  async function condition(el, width) {
3
4
  const actualWidth = await el.getSize('width');
4
5
  return {
@@ -6,7 +7,7 @@ async function condition(el, width) {
6
7
  result: actualWidth === width,
7
8
  };
8
9
  }
9
- export async function toHaveWidth(received, expectedValue, options = {}) {
10
+ export async function toHaveWidth(received, expectedValue, options = DEFAULT_OPTIONS) {
10
11
  const isNot = this.isNot;
11
12
  const { expectation = 'width', verb = 'have' } = this;
12
13
  await options.beforeAssertion?.({
@@ -0,0 +1,9 @@
1
+ import { toMatchSnapshot as jestToMatchSnapshot, toMatchInlineSnapshot as jestToMatchInlineSnapshot } from 'jest-snapshot';
2
+ export async function toMatchElementSnapshot(el, ...args) {
3
+ this.expectation = this.expectation || 'matchElementSnapshot';
4
+ return jestToMatchSnapshot.call(this, await el.getHTML(), ...args);
5
+ }
6
+ export async function toMatchElementInlineSnapshot(el, ...args) {
7
+ this.expectation = this.expectation || 'matchElementInlineSnapshot';
8
+ return jestToMatchInlineSnapshot.call(this, await el.getHTML(), ...args);
9
+ }
@@ -1,6 +1,7 @@
1
1
  import { waitUntil, enhanceError, compareNumbers, numberError, updateElementsArray } from '../../utils.js';
2
2
  import { refetchElements } from '../../util/refetchElements.js';
3
- export async function toBeElementsArrayOfSize(received, expectedValue, options = {}) {
3
+ import { DEFAULT_OPTIONS } from '../../constants.js';
4
+ export async function toBeElementsArrayOfSize(received, expectedValue, options = DEFAULT_OPTIONS) {
4
5
  const isNot = this.isNot;
5
6
  const { expectation = 'elements array of size', verb = 'be' } = this;
6
7
  await options.beforeAssertion?.({
@@ -0,0 +1,9 @@
1
+ import { toMatchSnapshot as jestToMatchSnapshot, toMatchInlineSnapshot as jestToMatchInlineSnapshot } from 'jest-snapshot';
2
+ export async function toMatchSnapshot(received, ...args) {
3
+ this.expectation = this.expectation || 'matchSnapshot';
4
+ return jestToMatchSnapshot.call(this, await received, ...args);
5
+ }
6
+ export async function toMatchInlineSnapshot(received, ...args) {
7
+ this.expectation = this.expectation || 'matchInlineSnapshot';
8
+ return jestToMatchInlineSnapshot.call(this, await received, ...args);
9
+ }
@@ -1,4 +1,5 @@
1
1
  import { toBeRequestedTimes } from './toBeRequestedTimes.js';
2
- export function toBeRequested(received, options = {}) {
2
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
+ export function toBeRequested(received, options = DEFAULT_OPTIONS) {
3
4
  return toBeRequestedTimes.call({ ...(this || {}), expectation: 'called' }, received, { gte: 1 }, options);
4
5
  }
@@ -1,6 +1,7 @@
1
1
  import { waitUntil, enhanceError, compareNumbers } from '../../utils.js';
2
2
  import { numberError } from '../../util/formatMessage.js';
3
- export async function toBeRequestedTimes(received, expectedValue = {}, options = {}) {
3
+ import { DEFAULT_OPTIONS } from '../../constants.js';
4
+ export async function toBeRequestedTimes(received, expectedValue = {}, options = DEFAULT_OPTIONS) {
4
5
  const isNot = this.isNot || false;
5
6
  const { expectation = `called${typeof expectedValue === 'number' ? ' ' + expectedValue : ''} time${expectedValue !== 1 ? 's' : ''}`, verb = 'be' } = this;
6
7
  await options.beforeAssertion?.({
@@ -1,8 +1,9 @@
1
1
  import { waitUntil, enhanceError } from '../../utils.js';
2
2
  import { equals } from '../../jasmineUtils.js';
3
+ import { DEFAULT_OPTIONS } from '../../constants.js';
3
4
  const STR_LIMIT = 80;
4
5
  const KEY_LIMIT = 12;
5
- export async function toBeRequestedWith(received, expectedValue = {}, options = {}) {
6
+ export async function toBeRequestedWith(received, expectedValue = {}, options = DEFAULT_OPTIONS) {
6
7
  const isNot = this.isNot || false;
7
8
  const { expectation = 'called with', verb = 'be' } = this;
8
9
  await options.beforeAssertion?.({
package/lib/matchers.js CHANGED
@@ -16,6 +16,7 @@ import * as toHaveClass from './matchers/element/toHaveClass.js';
16
16
  import * as toHaveHref from './matchers/element/toHaveHref.js';
17
17
  import * as toHaveId from './matchers/element/toHaveId.js';
18
18
  import * as toHaveSize from './matchers/element/toHaveSize.js';
19
+ import * as toMatchElementSnapshot from './matchers/element/toMatchElementSnapshot.js';
19
20
  import * as toHaveElementProperty from './matchers/element/toHaveElementProperty.js';
20
21
  import * as toHaveText from './matchers/element/toHaveText.js';
21
22
  import * as toHaveValue from './matchers/element/toHaveValue.js';
@@ -23,7 +24,9 @@ import * as toHaveStyle from './matchers/element/toHaveStyle.js';
23
24
  import * as toBeRequested from './matchers/mock/toBeRequested.js';
24
25
  import * as toBeRequestedTimes from './matchers/mock/toBeRequestedTimes.js';
25
26
  import * as toBeRequestedWith from './matchers/mock/toBeRequestedWith.js';
27
+ import * as toMatchSnapshot from './matchers/general/toMatchSnapshot.js';
26
28
  const matchers = {
29
+ ...toMatchSnapshot,
27
30
  ...toHaveClipboardText,
28
31
  ...toHaveTitle,
29
32
  ...toHaveUrl,
@@ -46,6 +49,7 @@ const matchers = {
46
49
  ...toHaveText,
47
50
  ...toHaveValue,
48
51
  ...toHaveStyle,
52
+ ...toMatchElementSnapshot,
49
53
  ...toBeRequested,
50
54
  ...toBeRequestedTimes,
51
55
  ...toBeRequestedWith,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "4.6.0",
3
+ "version": "4.7.0",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -77,7 +77,7 @@
77
77
  "shelljs": "^0.8.5",
78
78
  "typescript": "^5.2.2",
79
79
  "vitest": "0.34.6",
80
- "webdriverio": "8.23.1"
80
+ "webdriverio": "8.24.6"
81
81
  },
82
82
  "optionalDependencies": {
83
83
  "@wdio/globals": "^8.23.1",
@@ -85,7 +85,8 @@
85
85
  "webdriverio": "^8.23.1"
86
86
  },
87
87
  "dependencies": {
88
- "expect": "^29.7.0",
88
+ "jest-snapshot": "^29.7.0",
89
+ "@jest/expect": "^29.7.0",
89
90
  "jest-matcher-utils": "^29.7.0",
90
91
  "lodash.isequal": "^4.5.0"
91
92
  }
@@ -1,7 +1,5 @@
1
1
  declare namespace ExpectWebdriverIO {
2
- function expect<T = unknown, R extends void | Promise<void> = void | Promise<void>>(
3
- actual: T
4
- ): Matchers<R, T>
2
+ const expect: ExpectWebdriverIO.Expect
5
3
  function setOptions(options: DefaultOptions): void
6
4
  function getConfig(): any
7
5
 
@@ -145,6 +143,29 @@ declare namespace ExpectWebdriverIO {
145
143
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
146
144
  interface Matchers<R, T> {
147
145
  // ===== $ or $$ =====
146
+ /**
147
+ * This ensures that element html value matches the most recent snapshot with property matchers.
148
+ */
149
+ toMatchElementSnapshot(hint?: string): R;
150
+ /**
151
+ * This ensures that element html matches the most recent snapshot.
152
+ */
153
+ toMatchElementSnapshot<U extends Record<keyof T, unknown>>(
154
+ propertyMatchers: Partial<U>,
155
+ hint?: string,
156
+ ): R;
157
+ /**
158
+ * This ensures that element html matches the most recent snapshot with property matchers.
159
+ */
160
+ toMatchElementInlineSnapshot(snapshot?: string): R;
161
+ /**
162
+ * This ensures that element html matches the most recent snapshot with property matchers.
163
+ */
164
+ toMatchElementInlineSnapshot<U extends Record<keyof T, unknown>>(
165
+ propertyMatchers: Partial<U>,
166
+ snapshot?: string,
167
+ ): R;
168
+
148
169
  /**
149
170
  * `WebdriverIO.Element` -> `isDisplayed`
150
171
  */
@@ -487,23 +508,23 @@ declare namespace ExpectWebdriverIO {
487
508
  method?: string | Array<string>
488
509
  statusCode?: number | Array<number>
489
510
  requestHeaders?:
490
- | Record<string, string>
491
- | ExpectWebdriverIO.PartialMatcher
492
- | ((headers: Record<string, string>) => boolean)
511
+ | Record<string, string>
512
+ | ExpectWebdriverIO.PartialMatcher
513
+ | ((headers: Record<string, string>) => boolean)
493
514
  responseHeaders?:
494
- | Record<string, string>
495
- | ExpectWebdriverIO.PartialMatcher
496
- | ((headers: Record<string, string>) => boolean)
515
+ | Record<string, string>
516
+ | ExpectWebdriverIO.PartialMatcher
517
+ | ((headers: Record<string, string>) => boolean)
497
518
  postData?:
498
- | string
499
- | ExpectWebdriverIO.JsonCompatible
500
- | ExpectWebdriverIO.PartialMatcher
501
- | ((r: string | undefined) => boolean)
519
+ | string
520
+ | ExpectWebdriverIO.JsonCompatible
521
+ | ExpectWebdriverIO.PartialMatcher
522
+ | ((r: string | undefined) => boolean)
502
523
  response?:
503
- | string
504
- | ExpectWebdriverIO.JsonCompatible
505
- | ExpectWebdriverIO.PartialMatcher
506
- | ((r: string) => boolean)
524
+ | string
525
+ | ExpectWebdriverIO.JsonCompatible
526
+ | ExpectWebdriverIO.PartialMatcher
527
+ | ((r: string) => boolean)
507
528
  }
508
529
 
509
530
  type jsonPrimitive = string | number | boolean | null
@@ -1,7 +1,5 @@
1
1
  /// <reference types="./standalone.js"/>
2
2
 
3
- declare const expect: ExpectWebdriverIO.Expect
4
-
5
3
  declare namespace NodeJS {
6
4
  interface Global {
7
5
  expect: ExpectWebdriverIO.Expect;
@@ -4,13 +4,13 @@ type ChainablePromiseElement = import('webdriverio').ChainablePromiseElement<Web
4
4
  type ChainablePromiseArray = import('webdriverio').ChainablePromiseArray<WebdriverIO.Element>
5
5
 
6
6
  declare namespace ExpectWebdriverIO {
7
- interface Matchers<R extends void | Promise<void>, T> extends Readonly<import('expect').Matchers<R>> {
7
+ interface Matchers<R extends void | Promise<void>, T> extends Readonly<import('expect').Matchers<R, T>>, Readonly<import('jest-snapshot').SnapshotMatchers<R, T>> {
8
8
  not: Matchers<R, T>
9
9
  resolves: Matchers<R, T>
10
10
  rejects: Matchers<R, T>
11
11
  }
12
12
 
13
- type Expect = {
13
+ type Expect = Readonly<import('@jest/expect').JestExpect> & {
14
14
  <T = unknown, R extends void | Promise<void> = void | Promise<void>>(actual: T): Matchers<R, T>
15
15
  extend(map: Record<string, Function>): void
16
16
  } & AsymmetricMatchers