|
1 | 1 | import { test, expect, vi, describe } from 'vitest' |
2 | 2 | import { matchers, expect as expectLib } from '../src/index.js' |
3 | | -import { $ } from '@wdio/globals' |
| 3 | +import { $, $$ } from '@wdio/globals' |
4 | 4 |
|
5 | 5 | vi.mock('@wdio/globals') |
6 | 6 |
|
@@ -110,6 +110,19 @@ describe('Custom Wdio Matchers Integration Tests', async () => { |
110 | 110 | await expectLib(el).toHaveAttr('someAttribute', 'some attribute') |
111 | 111 | await expectLib(el).toHaveElementProperty('someProperty', '1') |
112 | 112 | }) |
| 113 | + |
| 114 | + test('toHave works with stringContaining asymmetric matcher', async () => { |
| 115 | + await expectLib(el).toHaveText([expectLib.stringContaining('Valid'), expectLib.stringContaining('Valid')]) |
| 116 | + }) |
| 117 | + |
| 118 | + // TODO to support one day? |
| 119 | + test('toHave works with arrayContaining asymmetric matcher', async () => { |
| 120 | + await expectLib(el).toHaveText( |
| 121 | + expectLib.arrayContaining([ |
| 122 | + expectLib.stringContaining('Valid'), |
| 123 | + expectLib.stringContaining('Valid') |
| 124 | + ])) |
| 125 | + }) |
113 | 126 | }) |
114 | 127 |
|
115 | 128 | describe('Matchers fails when using `.not` with proper message', async () => { |
@@ -458,4 +471,45 @@ Received: "not displayed"`) |
458 | 471 | expect(el.isDisplayed).toHaveBeenCalledTimes(6) |
459 | 472 | }) |
460 | 473 | }) |
| 474 | + |
| 475 | + describe('Matchers pass with success when using valid element array', async () => { |
| 476 | + const elements = await $$('selector') |
| 477 | + |
| 478 | + test('toBe matchers', async () => { |
| 479 | + await expectLib(elements).toBeDisplayed() |
| 480 | + await expectLib(elements).toBeExisting() |
| 481 | + await expectLib(elements).toBeEnabled() |
| 482 | + await expectLib(elements).toBeClickable() |
| 483 | + await expectLib(elements).toBeFocused() |
| 484 | + await expectLib(elements).toBeSelected() |
| 485 | + }) |
| 486 | + |
| 487 | + test('toHave matchers', async () => { |
| 488 | + await expectLib(elements).toHaveText('Valid Text') |
| 489 | + await expectLib(elements).toHaveHTML('<Html/>') |
| 490 | + await expectLib(elements).toHaveComputedLabel('Computed Label') |
| 491 | + await expectLib(elements).toHaveComputedRole('Computed Role') |
| 492 | + await expectLib(elements).toHaveSize({ width: 100, height: 50 }) |
| 493 | + await expectLib(elements).toHaveHeight(50) |
| 494 | + await expectLib(elements).toHaveWidth(100) |
| 495 | + await expectLib(elements).toHaveAttribute('someAttribute', 'some attribute') |
| 496 | + await expectLib(elements).toHaveAttribute('someAttribute') |
| 497 | + await expectLib(elements).toHaveAttr('someAttribute', 'some attribute') |
| 498 | + await expectLib(elements).toHaveElementProperty('someProperty', '1') |
| 499 | + await expectLib(elements).toBeElementsArrayOfSize(2) |
| 500 | + }) |
| 501 | + |
| 502 | + test('toHave works with stringContaining asymmetric matcher', async () => { |
| 503 | + await expectLib(elements).toHaveText([expectLib.stringContaining('Valid'), expectLib.stringContaining('Valid')]) |
| 504 | + }) |
| 505 | + |
| 506 | + // TODO to support one day? |
| 507 | + test.skip('toHave works with arrayContaining asymmetric matcher', async () => { |
| 508 | + await expectLib(elements).toHaveText( |
| 509 | + expectLib.arrayContaining([ |
| 510 | + expectLib.stringContaining('Valid'), |
| 511 | + expectLib.stringContaining('Valid') |
| 512 | + ])) |
| 513 | + }) |
| 514 | + }) |
461 | 515 | }) |
0 commit comments