expect-webdriverio 5.7.0 → 6.0.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 (41) hide show
  1. package/README.md +16 -14
  2. package/lib/constants.js +4 -0
  3. package/lib/index.js +30 -18
  4. package/lib/matchers/asymmetrics/asymmetricsUtils.js +24 -0
  5. package/lib/matchers/asymmetrics/oneOf.js +51 -0
  6. package/lib/matchers/browser/toHaveClipboardText.js +8 -9
  7. package/lib/matchers/browser/toHaveLocalStorageItem.js +22 -14
  8. package/lib/matchers/browser/toHaveTitle.js +9 -10
  9. package/lib/matchers/browser/toHaveUrl.js +8 -9
  10. package/lib/matchers/element/toBeExisting.js +8 -3
  11. package/lib/matchers/element/toBeSelected.js +6 -13
  12. package/lib/matchers/element/toHaveAttribute.js +46 -45
  13. package/lib/matchers/element/toHaveChildren.js +30 -32
  14. package/lib/matchers/element/toHaveComputedLabel.js +21 -20
  15. package/lib/matchers/element/toHaveComputedRole.js +21 -20
  16. package/lib/matchers/element/toHaveElementClass.js +57 -0
  17. package/lib/matchers/element/toHaveElementProperty.js +40 -32
  18. package/lib/matchers/element/toHaveHTML.js +22 -23
  19. package/lib/matchers/element/toHaveHeight.js +23 -28
  20. package/lib/matchers/element/toHaveSize.js +16 -14
  21. package/lib/matchers/element/toHaveStyle.js +20 -14
  22. package/lib/matchers/element/toHaveText.js +26 -44
  23. package/lib/matchers/element/toHaveWidth.js +23 -28
  24. package/lib/matchers/elements/toBeElementsArrayOfSize.js +25 -30
  25. package/lib/matchers/mock/toBeRequestedTimes.js +12 -17
  26. package/lib/matchers/mock/toBeRequestedWith.js +8 -9
  27. package/lib/matchers/modifiers/some.js +15 -0
  28. package/lib/matchers.js +1 -1
  29. package/lib/tsconfig.build.tsbuildinfo +1 -1
  30. package/lib/util/commandOptionsUtils.js +6 -0
  31. package/lib/util/elementsUtil.js +74 -4
  32. package/lib/util/executeCommand.js +94 -6
  33. package/lib/util/formatMessage.js +87 -32
  34. package/lib/util/numberOptionsUtil.js +92 -0
  35. package/lib/util/refetchElements.js +30 -5
  36. package/lib/util/stringUtil.js +12 -0
  37. package/lib/util/waitUntil.js +44 -0
  38. package/lib/utils.js +84 -91
  39. package/package.json +11 -10
  40. package/types/expect-webdriverio.d.ts +587 -134
  41. package/lib/matchers/element/toHaveClass.js +0 -61
@@ -1,61 +0,0 @@
1
- import { DEFAULT_OPTIONS } from '../../constants.js';
2
- import { compareText, compareTextWithArray, enhanceError, executeCommand, isAsymmetricMatcher, waitUntil, wrapExpectedWithArray } from '../../utils.js';
3
- import { toHaveAttributeAndValue } from './toHaveAttribute.js';
4
- async function condition(el, attribute, value, options) {
5
- const actualClass = await el.getAttribute(attribute);
6
- if (typeof actualClass !== 'string') {
7
- return { result: false };
8
- }
9
- if (isAsymmetricMatcher(value)) {
10
- return compareText(actualClass, value, options);
11
- }
12
- const classes = actualClass.split(' ');
13
- const isValueInClasses = classes.some((t) => {
14
- return Array.isArray(value)
15
- ? compareTextWithArray(t, value, options).result
16
- : compareText(t, value, options).result;
17
- });
18
- return {
19
- value: actualClass,
20
- result: isValueInClasses
21
- };
22
- }
23
- export function toHaveClass(...args) {
24
- return toHaveElementClass.call(this || {}, ...args);
25
- }
26
- export async function toHaveElementClass(received, expectedValue, options = DEFAULT_OPTIONS) {
27
- const isNot = this.isNot;
28
- const { expectation = 'class', verb = 'have' } = this;
29
- await options.beforeAssertion?.({
30
- matcherName: 'toHaveElementClass',
31
- expectedValue,
32
- options,
33
- });
34
- const attribute = 'class';
35
- let el = await received?.getElement();
36
- let attr;
37
- const pass = await waitUntil(async () => {
38
- const result = await executeCommand.call(this, el, condition, options, [attribute, expectedValue, options]);
39
- el = result.el;
40
- attr = result.values;
41
- return result.success;
42
- }, isNot, options);
43
- const message = enhanceError(el, wrapExpectedWithArray(el, attr, expectedValue), attr, this, verb, expectation, '', options);
44
- const result = {
45
- pass,
46
- message: () => message
47
- };
48
- await options.afterAssertion?.({
49
- matcherName: 'toHaveElementClass',
50
- expectedValue,
51
- options,
52
- result
53
- });
54
- return result;
55
- }
56
- export function toHaveClassContaining(el, className, options = DEFAULT_OPTIONS) {
57
- return toHaveAttributeAndValue.call(this, el, 'class', className, {
58
- ...options,
59
- containing: true
60
- });
61
- }