expect-webdriverio 5.3.3 → 5.3.4

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 (81) hide show
  1. package/lib/{tsconfig.tsbuildinfo → tsconfig.build.tsbuildinfo} +1 -1
  2. package/package.json +2 -2
  3. package/types/expect-webdriverio.d.ts +27 -38
  4. package/types/standalone.d.ts +0 -2
  5. package/lib/test/__fixtures__/utils.js +0 -19
  6. package/lib/test/index.test.js +0 -8
  7. package/lib/test/matchers/beMatchers.test.js +0 -109
  8. package/lib/test/matchers/browser/toHaveClipboardText.test.js +0 -21
  9. package/lib/test/matchers/browserMatchers.test.js +0 -102
  10. package/lib/test/matchers/element/toBeDisabled.test.js +0 -121
  11. package/lib/test/matchers/element/toHaveAttribute.test.js +0 -131
  12. package/lib/test/matchers/element/toHaveChildren.test.js +0 -62
  13. package/lib/test/matchers/element/toHaveComputedLabel.test.js +0 -284
  14. package/lib/test/matchers/element/toHaveComputedRole.test.js +0 -284
  15. package/lib/test/matchers/element/toHaveElementClass.test.js +0 -125
  16. package/lib/test/matchers/element/toHaveElementProperty.test.js +0 -111
  17. package/lib/test/matchers/element/toHaveHTML.test.js +0 -291
  18. package/lib/test/matchers/element/toHaveHeight.test.js +0 -171
  19. package/lib/test/matchers/element/toHaveHref.test.js +0 -54
  20. package/lib/test/matchers/element/toHaveId.test.js +0 -54
  21. package/lib/test/matchers/element/toHaveSize.test.js +0 -109
  22. package/lib/test/matchers/element/toHaveStyle.test.js +0 -199
  23. package/lib/test/matchers/element/toHaveText.test.js +0 -333
  24. package/lib/test/matchers/element/toHaveValue.test.js +0 -81
  25. package/lib/test/matchers/element/toHaveWidth.test.js +0 -171
  26. package/lib/test/matchers/elements/toBeElementsArrayOfSize.test.js +0 -141
  27. package/lib/test/matchers/mock/toBeRequested.test.js +0 -73
  28. package/lib/test/matchers/mock/toBeRequestedTimes.test.js +0 -108
  29. package/lib/test/matchers/mock/toBeRequestedWith.test.js +0 -343
  30. package/lib/test/matchers.test.js +0 -54
  31. package/lib/test/snapshot.test.js +0 -53
  32. package/lib/test/softAssertions.test.js +0 -332
  33. package/lib/test/util/elementsUtil.test.js +0 -18
  34. package/lib/test/util/formatMessage.test.js +0 -96
  35. package/lib/test/util/refetchElements.test.js +0 -19
  36. package/lib/test/utils.test.js +0 -117
  37. /package/lib/{src/constants.js → constants.js} +0 -0
  38. /package/lib/{src/index.js → index.js} +0 -0
  39. /package/lib/{src/jasmineUtils.js → jasmineUtils.js} +0 -0
  40. /package/lib/{src/matchers → matchers}/browser/toHaveClipboardText.js +0 -0
  41. /package/lib/{src/matchers → matchers}/browser/toHaveTitle.js +0 -0
  42. /package/lib/{src/matchers → matchers}/browser/toHaveUrl.js +0 -0
  43. /package/lib/{src/matchers → matchers}/element/toBeClickable.js +0 -0
  44. /package/lib/{src/matchers → matchers}/element/toBeDisabled.js +0 -0
  45. /package/lib/{src/matchers → matchers}/element/toBeDisplayed.js +0 -0
  46. /package/lib/{src/matchers → matchers}/element/toBeDisplayedInViewport.js +0 -0
  47. /package/lib/{src/matchers → matchers}/element/toBeEnabled.js +0 -0
  48. /package/lib/{src/matchers → matchers}/element/toBeExisting.js +0 -0
  49. /package/lib/{src/matchers → matchers}/element/toBeFocused.js +0 -0
  50. /package/lib/{src/matchers → matchers}/element/toBeSelected.js +0 -0
  51. /package/lib/{src/matchers → matchers}/element/toHaveAttribute.js +0 -0
  52. /package/lib/{src/matchers → matchers}/element/toHaveChildren.js +0 -0
  53. /package/lib/{src/matchers → matchers}/element/toHaveClass.js +0 -0
  54. /package/lib/{src/matchers → matchers}/element/toHaveComputedLabel.js +0 -0
  55. /package/lib/{src/matchers → matchers}/element/toHaveComputedRole.js +0 -0
  56. /package/lib/{src/matchers → matchers}/element/toHaveElementProperty.js +0 -0
  57. /package/lib/{src/matchers → matchers}/element/toHaveHTML.js +0 -0
  58. /package/lib/{src/matchers → matchers}/element/toHaveHeight.js +0 -0
  59. /package/lib/{src/matchers → matchers}/element/toHaveHref.js +0 -0
  60. /package/lib/{src/matchers → matchers}/element/toHaveId.js +0 -0
  61. /package/lib/{src/matchers → matchers}/element/toHaveSize.js +0 -0
  62. /package/lib/{src/matchers → matchers}/element/toHaveStyle.js +0 -0
  63. /package/lib/{src/matchers → matchers}/element/toHaveText.js +0 -0
  64. /package/lib/{src/matchers → matchers}/element/toHaveValue.js +0 -0
  65. /package/lib/{src/matchers → matchers}/element/toHaveWidth.js +0 -0
  66. /package/lib/{src/matchers → matchers}/elements/toBeElementsArrayOfSize.js +0 -0
  67. /package/lib/{src/matchers → matchers}/mock/toBeRequested.js +0 -0
  68. /package/lib/{src/matchers → matchers}/mock/toBeRequestedTimes.js +0 -0
  69. /package/lib/{src/matchers → matchers}/mock/toBeRequestedWith.js +0 -0
  70. /package/lib/{src/matchers → matchers}/snapshot.js +0 -0
  71. /package/lib/{src/matchers.js → matchers.js} +0 -0
  72. /package/lib/{src/snapshot.js → snapshot.js} +0 -0
  73. /package/lib/{src/softAssert.js → softAssert.js} +0 -0
  74. /package/lib/{src/softAssertService.js → softAssertService.js} +0 -0
  75. /package/lib/{src/softExpect.js → softExpect.js} +0 -0
  76. /package/lib/{src/types.js → types.js} +0 -0
  77. /package/lib/{src/util → util}/elementsUtil.js +0 -0
  78. /package/lib/{src/util → util}/executeCommand.js +0 -0
  79. /package/lib/{src/util → util}/formatMessage.js +0 -0
  80. /package/lib/{src/util → util}/refetchElements.js +0 -0
  81. /package/lib/{src/utils.js → utils.js} +0 -0
@@ -1 +1 @@
1
- {"root":["../test/index.test.ts","../test/matchers.test.ts","../test/snapshot.test.ts","../test/softAssertions.test.ts","../test/utils.test.ts","../test/__fixtures__/utils.ts","../test/matchers/beMatchers.test.ts","../test/matchers/browserMatchers.test.ts","../test/matchers/browser/toHaveClipboardText.test.ts","../test/matchers/element/toBeDisabled.test.ts","../test/matchers/element/toHaveAttribute.test.ts","../test/matchers/element/toHaveChildren.test.ts","../test/matchers/element/toHaveComputedLabel.test.ts","../test/matchers/element/toHaveComputedRole.test.ts","../test/matchers/element/toHaveElementClass.test.ts","../test/matchers/element/toHaveElementProperty.test.ts","../test/matchers/element/toHaveHTML.test.ts","../test/matchers/element/toHaveHeight.test.ts","../test/matchers/element/toHaveHref.test.ts","../test/matchers/element/toHaveId.test.ts","../test/matchers/element/toHaveSize.test.ts","../test/matchers/element/toHaveStyle.test.ts","../test/matchers/element/toHaveText.test.ts","../test/matchers/element/toHaveValue.test.ts","../test/matchers/element/toHaveWidth.test.ts","../test/matchers/elements/toBeElementsArrayOfSize.test.ts","../test/matchers/mock/toBeRequested.test.ts","../test/matchers/mock/toBeRequestedTimes.test.ts","../test/matchers/mock/toBeRequestedWith.test.ts","../test/util/elementsUtil.test.ts","../test/util/formatMessage.test.ts","../test/util/refetchElements.test.ts","../src/constants.ts","../src/index.ts","../src/jasmineUtils.ts","../src/matchers.ts","../src/snapshot.ts","../src/softAssert.ts","../src/softAssertService.ts","../src/softExpect.ts","../src/types.ts","../src/utils.ts","../src/matchers/snapshot.ts","../src/matchers/browser/toHaveClipboardText.ts","../src/matchers/browser/toHaveTitle.ts","../src/matchers/browser/toHaveUrl.ts","../src/matchers/element/toBeClickable.ts","../src/matchers/element/toBeDisabled.ts","../src/matchers/element/toBeDisplayed.ts","../src/matchers/element/toBeDisplayedInViewport.ts","../src/matchers/element/toBeEnabled.ts","../src/matchers/element/toBeExisting.ts","../src/matchers/element/toBeFocused.ts","../src/matchers/element/toBeSelected.ts","../src/matchers/element/toHaveAttribute.ts","../src/matchers/element/toHaveChildren.ts","../src/matchers/element/toHaveClass.ts","../src/matchers/element/toHaveComputedLabel.ts","../src/matchers/element/toHaveComputedRole.ts","../src/matchers/element/toHaveElementProperty.ts","../src/matchers/element/toHaveHTML.ts","../src/matchers/element/toHaveHeight.ts","../src/matchers/element/toHaveHref.ts","../src/matchers/element/toHaveId.ts","../src/matchers/element/toHaveSize.ts","../src/matchers/element/toHaveStyle.ts","../src/matchers/element/toHaveText.ts","../src/matchers/element/toHaveValue.ts","../src/matchers/element/toHaveWidth.ts","../src/matchers/elements/toBeElementsArrayOfSize.ts","../src/matchers/mock/toBeRequested.ts","../src/matchers/mock/toBeRequestedTimes.ts","../src/matchers/mock/toBeRequestedWith.ts","../src/util/elementsUtil.ts","../src/util/executeCommand.ts","../src/util/formatMessage.ts","../src/util/refetchElements.ts"],"version":"5.8.3"}
1
+ {"root":["../src/constants.ts","../src/index.ts","../src/jasmineUtils.ts","../src/matchers.ts","../src/snapshot.ts","../src/softAssert.ts","../src/softAssertService.ts","../src/softExpect.ts","../src/types.ts","../src/utils.ts","../src/matchers/snapshot.ts","../src/matchers/browser/toHaveClipboardText.ts","../src/matchers/browser/toHaveTitle.ts","../src/matchers/browser/toHaveUrl.ts","../src/matchers/element/toBeClickable.ts","../src/matchers/element/toBeDisabled.ts","../src/matchers/element/toBeDisplayed.ts","../src/matchers/element/toBeDisplayedInViewport.ts","../src/matchers/element/toBeEnabled.ts","../src/matchers/element/toBeExisting.ts","../src/matchers/element/toBeFocused.ts","../src/matchers/element/toBeSelected.ts","../src/matchers/element/toHaveAttribute.ts","../src/matchers/element/toHaveChildren.ts","../src/matchers/element/toHaveClass.ts","../src/matchers/element/toHaveComputedLabel.ts","../src/matchers/element/toHaveComputedRole.ts","../src/matchers/element/toHaveElementProperty.ts","../src/matchers/element/toHaveHTML.ts","../src/matchers/element/toHaveHeight.ts","../src/matchers/element/toHaveHref.ts","../src/matchers/element/toHaveId.ts","../src/matchers/element/toHaveSize.ts","../src/matchers/element/toHaveStyle.ts","../src/matchers/element/toHaveText.ts","../src/matchers/element/toHaveValue.ts","../src/matchers/element/toHaveWidth.ts","../src/matchers/elements/toBeElementsArrayOfSize.ts","../src/matchers/mock/toBeRequested.ts","../src/matchers/mock/toBeRequestedTimes.ts","../src/matchers/mock/toBeRequestedWith.ts","../src/util/elementsUtil.ts","../src/util/executeCommand.ts","../src/util/formatMessage.ts","../src/util/refetchElements.ts"],"version":"5.8.3"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "5.3.3",
3
+ "version": "5.3.4",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "clean": "run-p clean:*",
46
46
  "clean:build": "rimraf ./lib",
47
47
  "clean:tests": "rimraf test-types/**/node_modules && rimraf test-types/**/dist",
48
- "compile": "tsc --build tsconfig.json",
48
+ "compile": "tsc --build tsconfig.build.json",
49
49
  "test": "run-s test:*",
50
50
  "test:lint": "eslint .",
51
51
  "test:unit": "vitest --run",
@@ -1,16 +1,14 @@
1
- /* eslint-disable @typescript-eslint/consistent-type-imports*/
2
- type ServiceInstance = import('@wdio/types').Services.ServiceInstance
3
- type Test = import('@wdio/types').Frameworks.Test
4
- type TestResult = import('@wdio/types').Frameworks.TestResult
5
- type PickleStep = import('@wdio/types').Frameworks.PickleStep
6
- type Scenario = import('@wdio/types').Frameworks.Scenario
7
- type SnapshotResult = import('@vitest/snapshot').SnapshotResult
8
- type SnapshotUpdateState = import('@vitest/snapshot').SnapshotUpdateState
1
+ type ServiceInstance = import('@wdio/types').Services.ServiceInstance;
2
+ type Test = import('@wdio/types').Frameworks.Test;
3
+ type TestResult = import('@wdio/types').Frameworks.TestResult;
4
+ type PickleStep = import('@wdio/types').Frameworks.PickleStep;
5
+ type Scenario = import('@wdio/types').Frameworks.Scenario;
6
+ type SnapshotResult = import('@vitest/snapshot').SnapshotResult;
7
+ type SnapshotUpdateState = import('@vitest/snapshot').SnapshotUpdateState;
9
8
 
10
9
  declare namespace ExpectWebdriverIO {
11
10
  const expect: ExpectWebdriverIO.Expect
12
11
  function setOptions(options: DefaultOptions): void
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
12
  function getConfig(): any
15
13
 
16
14
  interface SnapshotServiceArgs {
@@ -25,34 +23,32 @@ declare namespace ExpectWebdriverIO {
25
23
  }
26
24
 
27
25
  interface SoftFailure {
28
- error: Error
29
- matcherName: string
30
- location?: string
26
+ error: Error;
27
+ matcherName: string;
28
+ location?: string;
31
29
  }
32
30
 
33
31
  class SoftAssertService {
34
- static getInstance(): SoftAssertService
35
- setCurrentTest(testId: string, testName?: string, testFile?: string): void
36
- clearCurrentTest(): void
37
- getCurrentTestId(): string | null
38
- addFailure(error: Error, matcherName: string): void
39
- getFailures(testId?: string): SoftFailure[]
40
- clearFailures(testId?: string): void
41
- assertNoFailures(testId?: string): void
32
+ static getInstance(): SoftAssertService;
33
+ setCurrentTest(testId: string, testName?: string, testFile?: string): void;
34
+ clearCurrentTest(): void;
35
+ getCurrentTestId(): string | null;
36
+ addFailure(error: Error, matcherName: string): void;
37
+ getFailures(testId?: string): SoftFailure[];
38
+ clearFailures(testId?: string): void;
39
+ assertNoFailures(testId?: string): void;
42
40
  }
43
41
 
44
42
  interface SoftAssertionServiceOptions {
45
- autoAssertOnTestEnd?: boolean
43
+ autoAssertOnTestEnd?: boolean;
46
44
  }
47
45
 
48
46
  class SoftAssertionService implements ServiceInstance {
49
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
- constructor(serviceOptions?: SoftAssertionServiceOptions, capabilities?: any, config?: any)
51
- beforeTest(test: Test): void
52
- beforeStep(step: PickleStep, scenario: Scenario): void
53
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- afterTest(test: Test, context: any, result: TestResult): void
55
- afterStep(step: PickleStep, scenario: Scenario, result: { passed: boolean, error?: Error }): void
47
+ constructor(serviceOptions?: SoftAssertionServiceOptions, capabilities?: any, config?: any);
48
+ beforeTest(test: Test): void;
49
+ beforeStep(step: PickleStep, scenario: Scenario): void;
50
+ afterTest(test: Test, context: any, result: TestResult): void;
51
+ afterStep(step: PickleStep, scenario: Scenario, result: { passed: boolean, error?: Error }): void;
56
52
  }
57
53
 
58
54
  interface AssertionResult {
@@ -63,9 +59,7 @@ declare namespace ExpectWebdriverIO {
63
59
  const matchers: Map<
64
60
  string,
65
61
  (
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
62
  actual: any,
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
63
  ...expected: any[]
70
64
  ) => Promise<AssertionResult>
71
65
  >
@@ -85,7 +79,6 @@ declare namespace ExpectWebdriverIO {
85
79
  * expect(el).toHaveAttribute('attr', 'value', { ... }) // expectedValue is `['attr', 'value]`
86
80
  * ```
87
81
  */
88
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
82
  expectedValue?: any,
90
83
  /**
91
84
  * Options that the user has passed in, e.g. `expect(el).toHaveText('foo', { ignoreCase: true })` -> `{ ignoreCase: true }`
@@ -245,10 +238,10 @@ declare namespace ExpectWebdriverIO {
245
238
  * **Usage**
246
239
  * ```js
247
240
  * // Check if an element has the class 'btn'
248
- * await expect(element).toHaveElementClass('btn')
241
+ * await expect(element).toHaveElementClass('btn');
249
242
  *
250
243
  * // Check if an element has any of the specified classes
251
- * await expect(element).toHaveElementClass(['btn', 'btn-large'])
244
+ * await expect(element).toHaveElementClass(['btn', 'btn-large']);
252
245
  * ```
253
246
  */
254
247
  toHaveElementClass(className: string | RegExp | Array<string | RegExp> | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
@@ -258,7 +251,6 @@ declare namespace ExpectWebdriverIO {
258
251
  */
259
252
  toHaveElementProperty(
260
253
  property: string | RegExp | ExpectWebdriverIO.PartialMatcher,
261
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
262
254
  value?: any,
263
255
  options?: ExpectWebdriverIO.StringOptions
264
256
  ): R
@@ -426,7 +418,7 @@ declare namespace ExpectWebdriverIO {
426
418
  toBeElementsArrayOfSize(
427
419
  size: number | ExpectWebdriverIO.NumberOptions,
428
420
  options?: ExpectWebdriverIO.NumberOptions
429
- ): R & Promise<WebdriverIO.ElementArray>
421
+ ): R & Promise<WebdriverIO.ElementArray>;
430
422
 
431
423
  // ==== network mock ====
432
424
  /**
@@ -487,10 +479,8 @@ declare namespace ExpectWebdriverIO {
487
479
  type JsonCompatible = jsonObject | jsonArray
488
480
 
489
481
  interface PartialMatcher {
490
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
491
482
  sample?: any
492
483
  $$typeof: symbol
493
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
494
484
  asymmetricMatch(...args: any[]): boolean
495
485
  toString(): string
496
486
  }
@@ -537,7 +527,6 @@ declare namespace ExpectWebdriverIO {
537
527
  }
538
528
 
539
529
  interface AsymmetricMatchers {
540
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
541
530
  any(expectedObject: any): PartialMatcher
542
531
  anything(): PartialMatcher
543
532
  arrayContaining(sample: Array<unknown>): PartialMatcher
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/consistent-type-imports*/
2
1
  /// <reference types="./expect-webdriverio.js"/>
3
2
 
4
3
  type ChainablePromiseElement = import('webdriverio').ChainablePromiseElement<WebdriverIO.Element>
@@ -22,7 +21,6 @@ declare namespace ExpectWebdriverIO {
22
21
  } & AsymmetricMatchers
23
22
 
24
23
  interface AsymmetricMatchers {
25
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
24
  any(expectedObject: any): PartialMatcher
27
25
  anything(): PartialMatcher
28
26
  arrayContaining(sample: Array<unknown>): PartialMatcher
@@ -1,19 +0,0 @@
1
- export function matcherNameToString(matcherName) {
2
- return matcherName.replace(/([A-Z])/g, ' $1').toLowerCase();
3
- }
4
- export function getExpectMessage(msg) {
5
- return msg.split('\n')[0];
6
- }
7
- export function getExpected(msg) {
8
- return getReceivedOrExpected(msg, 'Expected');
9
- }
10
- export function getReceived(msg) {
11
- return getReceivedOrExpected(msg, 'Received');
12
- }
13
- function getReceivedOrExpected(msg, type) {
14
- return msg.split('\n').find((line, idx) => idx > 1 && line.startsWith(type));
15
- }
16
- export function removeColors(msg) {
17
- const s = msg.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
18
- return s;
19
- }
@@ -1,8 +0,0 @@
1
- import { test, expect } from 'vitest';
2
- import { setOptions, expect as expectExport, matchers, utils } from '../src/index.js';
3
- test('index', () => {
4
- expect(setOptions.name).toBe('setDefaultOptions');
5
- expect(expectExport).toBeDefined();
6
- expect(utils.compareText).toBeDefined();
7
- expect(matchers.size).toEqual(41);
8
- });
@@ -1,109 +0,0 @@
1
- import { vi, test, describe, expect } from 'vitest';
2
- import { $ } from '@wdio/globals';
3
- import { getExpectMessage, getReceived, matcherNameToString } from '../__fixtures__/utils.js';
4
- import * as Matchers from '../../src/matchers.js';
5
- vi.mock('@wdio/globals');
6
- const ignoredMatchers = ['toBeElementsArrayOfSize', 'toBeDisabled', 'toBeRequested', 'toBeRequestedTimes', 'toBeRequestedWithResponse', 'toBeRequestedWith'];
7
- const beMatchers = [
8
- ...Object.keys(Matchers).filter(name => name.startsWith('toBe') && !ignoredMatchers.includes(name)),
9
- 'toExist'
10
- ];
11
- describe('be* matchers', () => {
12
- beMatchers.forEach((name) => {
13
- const fn = Matchers[name];
14
- describe(name, () => {
15
- test('wait for success', async () => {
16
- const el = await $('sel');
17
- el._attempts = 2;
18
- el._value = function () {
19
- if (this._attempts > 0) {
20
- this._attempts--;
21
- return false;
22
- }
23
- return true;
24
- };
25
- const result = await fn.call({}, el);
26
- expect(result.pass).toBe(true);
27
- expect(el._attempts).toBe(0);
28
- });
29
- test('wait but failure', async () => {
30
- const el = await $('sel');
31
- el._value = function () {
32
- throw new Error('some error');
33
- };
34
- await expect(() => fn.call({}, el, 10, {}))
35
- .rejects.toThrow('some error');
36
- });
37
- test('success on the first attempt', async () => {
38
- const el = await $('sel');
39
- el._attempts = 0;
40
- el._value = function () {
41
- this._attempts++;
42
- return true;
43
- };
44
- const result = await fn.call({}, el);
45
- expect(result.pass).toBe(true);
46
- expect(el._attempts).toBe(1);
47
- });
48
- test('no wait - failure', async () => {
49
- const el = await $('sel');
50
- el._attempts = 0;
51
- el._value = function () {
52
- this._attempts++;
53
- return false;
54
- };
55
- const result = await fn.call({}, el, { wait: 0 });
56
- expect(result.pass).toBe(false);
57
- expect(el._attempts).toBe(1);
58
- });
59
- test('no wait - success', async () => {
60
- const el = await $('sel');
61
- el._attempts = 0;
62
- el._value = function () {
63
- this._attempts++;
64
- return true;
65
- };
66
- const result = await fn.call({}, el, { wait: 0 });
67
- expect(result.pass).toBe(true);
68
- expect(el._attempts).toBe(1);
69
- });
70
- test('not - failure', async () => {
71
- const result = await fn.call({ isNot: true }, $('sel'), { wait: 0 });
72
- const received = getReceived(result.message());
73
- expect(received).not.toContain('not');
74
- expect(result.pass).toBe(true);
75
- });
76
- test('not - success', async () => {
77
- const el = await $('sel');
78
- el._value = function () {
79
- return false;
80
- };
81
- const result = await fn.call({ isNot: true }, el, { wait: 0 });
82
- const received = getReceived(result.message());
83
- expect(received).toContain('not');
84
- expect(result.pass).toBe(false);
85
- });
86
- test('not - failure (with wait)', async () => {
87
- const result = await fn.call({ isNot: true }, $('sel'), { wait: 1 });
88
- const received = getReceived(result.message());
89
- expect(received).not.toContain('not');
90
- expect(result.pass).toBe(true);
91
- });
92
- test('not - success (with wait)', async () => {
93
- const el = await $('sel');
94
- el._value = function () {
95
- return false;
96
- };
97
- const result = await fn.call({ isNot: true }, el, { wait: 1 });
98
- const received = getReceived(result.message());
99
- expect(received).toContain('not');
100
- expect(result.pass).toBe(false);
101
- });
102
- test('message', async () => {
103
- const result = await fn.call({}, $('sel'));
104
- expect(getExpectMessage(result.message()))
105
- .toContain(matcherNameToString(name));
106
- });
107
- });
108
- });
109
- });
@@ -1,21 +0,0 @@
1
- import { vi, test, expect } from 'vitest';
2
- import { browser } from '@wdio/globals';
3
- import { toHaveClipboardText } from '../../../src/matchers/browser/toHaveClipboardText.js';
4
- vi.mock('@wdio/globals');
5
- const beforeAssertion = vi.fn();
6
- const afterAssertion = vi.fn();
7
- test('toHaveClipboardText', async () => {
8
- const result = await toHaveClipboardText.call({}, browser, 'some ClipBoard text', { ignoreCase: true, beforeAssertion, afterAssertion });
9
- expect(result.pass).toBe(true);
10
- expect(beforeAssertion).toBeCalledWith({
11
- matcherName: 'toHaveClipboardText',
12
- expectedValue: 'some ClipBoard text',
13
- options: { ignoreCase: true, beforeAssertion, afterAssertion }
14
- });
15
- expect(afterAssertion).toBeCalledWith({
16
- matcherName: 'toHaveClipboardText',
17
- expectedValue: 'some ClipBoard text',
18
- options: { ignoreCase: true, beforeAssertion, afterAssertion },
19
- result
20
- });
21
- });
@@ -1,102 +0,0 @@
1
- import { vi, test, describe, expect } from 'vitest';
2
- import { browser } from '@wdio/globals';
3
- import { getExpectMessage, getReceived, matcherNameToString, getExpected } from '../__fixtures__/utils.js';
4
- import * as Matchers from '../../src/matchers.js';
5
- vi.mock('@wdio/globals');
6
- const browserMatchers = ['toHaveUrl', 'toHaveTitle'];
7
- const validText = ' Valid Text ';
8
- const wrongText = ' Wrong Text ';
9
- describe('browser matchers', () => {
10
- browserMatchers.forEach((name) => {
11
- const fn = Matchers[name];
12
- describe(name, () => {
13
- test('wait for success', async () => {
14
- browser._attempts = 2;
15
- browser._value = function () {
16
- if (this._attempts > 0) {
17
- this._attempts--;
18
- return wrongText;
19
- }
20
- return validText;
21
- };
22
- const result = await fn.call({}, browser, validText, { trim: false });
23
- expect(result.pass).toBe(true);
24
- expect(browser._attempts).toBe(0);
25
- });
26
- test('wait but failure', async () => {
27
- browser._value = function () {
28
- throw new Error('some error');
29
- };
30
- await expect(() => fn.call({}, browser, validText, { trim: false }))
31
- .rejects.toThrow('some error');
32
- });
33
- test('success on the first attempt', async () => {
34
- browser._attempts = 0;
35
- browser._value = function () {
36
- this._attempts++;
37
- return validText;
38
- };
39
- const result = await fn.call({}, browser, validText, { trim: false });
40
- expect(result.pass).toBe(true);
41
- expect(browser._attempts).toBe(1);
42
- });
43
- test('no wait - failure', async () => {
44
- browser._attempts = 0;
45
- browser._value = function () {
46
- this._attempts++;
47
- return wrongText;
48
- };
49
- const result = await fn.call({}, browser, validText, { wait: 0, trim: false });
50
- expect(result.pass).toBe(false);
51
- expect(browser._attempts).toBe(1);
52
- });
53
- test('no wait - success', async () => {
54
- browser._attempts = 0;
55
- browser._value = function () {
56
- this._attempts++;
57
- return validText;
58
- };
59
- const result = await fn.call({}, browser, validText, { wait: 0, trim: false });
60
- expect(result.pass).toBe(true);
61
- expect(browser._attempts).toBe(1);
62
- });
63
- test('not - failure', async () => {
64
- const result = await fn.call({ isNot: true }, browser, validText, { wait: 0, trim: false });
65
- expect(getExpectMessage(result.message())).toContain('not');
66
- expect(getExpected(result.message())).toContain('not');
67
- expect(result.pass).toBe(true);
68
- });
69
- test('not - success', async () => {
70
- browser._value = function () {
71
- return wrongText;
72
- };
73
- const result = await fn.call({ isNot: true }, browser, validText, { wait: 0 });
74
- expect(getExpectMessage(result.message())).toContain('not');
75
- expect(getExpected(result.message())).toContain('Valid');
76
- expect(getReceived(result.message())).toContain('Wrong');
77
- expect(result.pass).toBe(false);
78
- });
79
- test('not - failure (with wait)', async () => {
80
- delete browser._value;
81
- const result = await fn.call({ isNot: true }, browser, validText, { wait: 1, trim: false });
82
- expect(getExpectMessage(result.message())).toContain('not');
83
- expect(getExpected(result.message())).toContain('not');
84
- expect(result.pass).toBe(true);
85
- });
86
- test('not - success (with wait)', async () => {
87
- browser._value = function () {
88
- return wrongText;
89
- };
90
- const result = await fn.call({ isNot: true }, browser, validText, { wait: 1 });
91
- expect(getExpectMessage(result.message())).toContain('not');
92
- expect(getExpected(result.message())).toContain('Valid');
93
- expect(getReceived(result.message())).toContain('Wrong');
94
- expect(result.pass).toBe(false);
95
- });
96
- test('message', async () => {
97
- const result = await fn.call({}, browser);
98
- expect(getExpectMessage(result.message())).toContain(matcherNameToString(name));
99
- });
100
- });
101
- });
102
- });
@@ -1,121 +0,0 @@
1
- import { vi, test, describe, expect } from 'vitest';
2
- import { $ } from '@wdio/globals';
3
- import { getExpectMessage, getReceived } from '../../__fixtures__/utils.js';
4
- import { toBeDisabled } from '../../../src/matchers/element/toBeDisabled.js';
5
- vi.mock('@wdio/globals');
6
- describe('toBeDisabled', () => {
7
- test('wait for success', async () => {
8
- const el = await $('sel');
9
- el._attempts = 2;
10
- el._value = function () {
11
- if (this._attempts > 0) {
12
- this._attempts--;
13
- return true;
14
- }
15
- return false;
16
- };
17
- const beforeAssertion = vi.fn();
18
- const afterAssertion = vi.fn();
19
- const result = await toBeDisabled.call({}, el, { beforeAssertion, afterAssertion });
20
- expect(result.pass).toBe(true);
21
- expect(el._attempts).toBe(0);
22
- expect(beforeAssertion).toBeCalledWith({
23
- matcherName: 'toBeDisabled',
24
- options: { beforeAssertion, afterAssertion }
25
- });
26
- expect(afterAssertion).toBeCalledWith({
27
- matcherName: 'toBeDisabled',
28
- options: { beforeAssertion, afterAssertion },
29
- result
30
- });
31
- });
32
- test('wait but failure', async () => {
33
- const el = await $('sel');
34
- el._value = function () {
35
- throw new Error('some error');
36
- };
37
- await expect(() => toBeDisabled.call({}, el))
38
- .rejects.toThrow('some error');
39
- });
40
- test('success on the first attempt', async () => {
41
- const el = await $('sel');
42
- el._attempts = 0;
43
- el._value = function () {
44
- this._attempts++;
45
- return false;
46
- };
47
- const result = await toBeDisabled.call({}, el);
48
- expect(result.pass).toBe(true);
49
- expect(el._attempts).toBe(1);
50
- });
51
- test('no wait - failure', async () => {
52
- const el = await $('sel');
53
- el._attempts = 0;
54
- el._value = function () {
55
- this._attempts++;
56
- return true;
57
- };
58
- const result = await toBeDisabled.call({}, el, { wait: 0 });
59
- expect(result.pass).toBe(false);
60
- expect(el._attempts).toBe(1);
61
- });
62
- test('no wait - success', async () => {
63
- const el = await $('sel');
64
- el._attempts = 0;
65
- el._value = function () {
66
- this._attempts++;
67
- return false;
68
- };
69
- const result = await toBeDisabled.call({}, el, { wait: 0 });
70
- expect(result.pass).toBe(true);
71
- expect(el._attempts).toBe(1);
72
- });
73
- test('not - failure', async () => {
74
- const el = await $('sel');
75
- el._value = function () {
76
- return false;
77
- };
78
- const result = await toBeDisabled.call({ isNot: true }, el, { wait: 0 });
79
- const received = getReceived(result.message());
80
- expect(received).not.toContain('not');
81
- expect(result.pass).toBe(true);
82
- });
83
- test('not - success', async () => {
84
- const el = await $('sel');
85
- el._value = function () {
86
- return true;
87
- };
88
- const result = await toBeDisabled.call({ isNot: true }, el, { wait: 0 });
89
- const received = getReceived(result.message());
90
- expect(received).toContain('not');
91
- expect(result.pass).toBe(false);
92
- });
93
- test('not - failure (with wait)', async () => {
94
- const el = await $('sel');
95
- el._value = function () {
96
- return false;
97
- };
98
- const result = await toBeDisabled.call({ isNot: true }, el, { wait: 1 });
99
- const received = getReceived(result.message());
100
- expect(received).not.toContain('not');
101
- expect(result.pass).toBe(true);
102
- });
103
- test('not - success (with wait)', async () => {
104
- const el = await $('sel');
105
- el._value = function () {
106
- return true;
107
- };
108
- const result = await toBeDisabled.call({ isNot: true }, el, { wait: 1 });
109
- const received = getReceived(result.message());
110
- expect(received).toContain('not');
111
- expect(result.pass).toBe(false);
112
- });
113
- test('message', async () => {
114
- const el = await $('sel');
115
- el._value = function () {
116
- return false;
117
- };
118
- const result = await toBeDisabled.call({}, el);
119
- expect(getExpectMessage(result.message())).toContain('to be disabled');
120
- });
121
- });