Skip to content

Commit dabec4a

Browse files
committed
Add asymmetric integration tests
1 parent 1393b73 commit dabec4a

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

test/matchers.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test, expect, vi, describe } from 'vitest'
22
import { matchers, expect as expectLib } from '../src/index.js'
3-
import { $ } from '@wdio/globals'
3+
import { $, $$ } from '@wdio/globals'
44

55
vi.mock('@wdio/globals')
66

@@ -110,6 +110,19 @@ describe('Custom Wdio Matchers Integration Tests', async () => {
110110
await expectLib(el).toHaveAttr('someAttribute', 'some attribute')
111111
await expectLib(el).toHaveElementProperty('someProperty', '1')
112112
})
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+
})
113126
})
114127

115128
describe('Matchers fails when using `.not` with proper message', async () => {
@@ -458,4 +471,45 @@ Received: "not displayed"`)
458471
expect(el.isDisplayed).toHaveBeenCalledTimes(6)
459472
})
460473
})
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+
})
461515
})

0 commit comments

Comments
 (0)