Skip to content

Commit ad9c9ac

Browse files
(fix): allow partial matcher type in matchers
1 parent d34afdb commit ad9c9ac

20 files changed

+72
-68
lines changed

src/matchers/browser/toHaveTitle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { waitUntil, enhanceError, compareText } from '../../utils.js'
22

3-
export async function toHaveTitle(browser: WebdriverIO.Browser, title: string | RegExp, options: ExpectWebdriverIO.StringOptions = {}) {
3+
export async function toHaveTitle(browser: WebdriverIO.Browser, title: string | RegExp | ExpectWebdriverIO.PartialMatcher, options: ExpectWebdriverIO.StringOptions = {}) {
44
const isNot = this.isNot
55
const { expectation = 'title', verb = 'have' } = this
66

src/matchers/browser/toHaveUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { waitUntil, enhanceError, compareText } from '../../utils.js'
22

3-
export async function toHaveUrl(browser: WebdriverIO.Browser, url: string | RegExp, options: ExpectWebdriverIO.StringOptions = {}) {
3+
export async function toHaveUrl(browser: WebdriverIO.Browser, url: string | RegExp | ExpectWebdriverIO.PartialMatcher, options: ExpectWebdriverIO.StringOptions = {}) {
44
const isNot = this.isNot
55
const { expectation = 'url', verb = 'have' } = this
66

src/matchers/element/toHaveAttribute.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function conditionAttr(el: WebdriverIO.Element, attribute: string) {
1212
}
1313
}
1414

15-
async function conditionAttrAndValue(el: WebdriverIO.Element, attribute: string, value: string | RegExp, options: ExpectWebdriverIO.StringOptions) {
15+
async function conditionAttrAndValue(el: WebdriverIO.Element, attribute: string, value: string | RegExp | ExpectWebdriverIO.PartialMatcher, options: ExpectWebdriverIO.StringOptions) {
1616
const attr = await el.getAttribute(attribute)
1717
if (typeof attr !== 'string') {
1818
return { result: false, value: attr }
@@ -21,7 +21,7 @@ async function conditionAttrAndValue(el: WebdriverIO.Element, attribute: string,
2121
return compareText(attr, value, options)
2222
}
2323

24-
export async function toHaveAttributeAndValueFn(received: WebdriverIO.Element | WebdriverIO.ElementArray, attribute: string, value: string | RegExp, options: ExpectWebdriverIO.StringOptions = {}) {
24+
export async function toHaveAttributeAndValueFn(received: WebdriverIO.Element | WebdriverIO.ElementArray, attribute: string, value: string | RegExp | ExpectWebdriverIO.PartialMatcher, options: ExpectWebdriverIO.StringOptions = {}) {
2525
const isNot = this.isNot
2626
const { expectation = 'attribute', verb = 'have' } = this
2727

src/matchers/element/toHaveClass.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray } from '../../utils.js'
1+
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, updateElementsArray, compareText } from '../../utils.js'
22

3-
async function condition(el: WebdriverIO.Element, attribute: string, value: string | RegExp, options: ExpectWebdriverIO.StringOptions) {
3+
async function condition(el: WebdriverIO.Element, attribute: string, value: string | RegExp | ExpectWebdriverIO.PartialMatcher, options: ExpectWebdriverIO.StringOptions) {
44
const { ignoreCase = false, trim = false, containing = false } = options
55

66
let attr = await el.getAttribute(attribute)
@@ -13,15 +13,19 @@ async function condition(el: WebdriverIO.Element, attribute: string, value: stri
1313
}
1414
if (ignoreCase) {
1515
attr = attr.toLowerCase()
16-
if (! (value instanceof RegExp)) {
16+
if (typeof value === 'string') {
1717
value = value.toLowerCase()
1818
}
1919
}
2020

2121
const classes = attr.split(' ')
2222

2323
const valueInClasses = classes.some((t) => {
24-
return value instanceof RegExp ? !!t.match(value) : containing ? t.includes(value) : t === value
24+
return value instanceof RegExp
25+
? !!t.match(value)
26+
: containing && typeof value === 'string'
27+
? t.includes(value)
28+
: compareText(t, value, options)
2529
})
2630
return {
2731
value: attr,
@@ -33,7 +37,7 @@ export function toHaveElementClass(...args: any): any {
3337
return toHaveClass.call(this || {}, ...args)
3438
}
3539

36-
export async function toHaveClass(received: WebdriverIO.Element | WebdriverIO.ElementArray, className: string | RegExp, options: ExpectWebdriverIO.StringOptions = {}) {
40+
export async function toHaveClass(received: WebdriverIO.Element | WebdriverIO.ElementArray, className: string | RegExp | ExpectWebdriverIO.PartialMatcher, options: ExpectWebdriverIO.StringOptions = {}) {
3741
const isNot = this.isNot
3842
const { expectation = 'class', verb = 'have' } = this
3943

src/matchers/element/toHaveClassContaining.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function toHaveElementClassContaining (...args: any) {
44
return toHaveClassContaining.call(this, ...args)
55
}
66

7-
export function toHaveClassContaining(el: WebdriverIO.Element, className: string | RegExp, options: ExpectWebdriverIO.StringOptions = {}) {
7+
export function toHaveClassContaining(el: WebdriverIO.Element, className: string | RegExp | ExpectWebdriverIO.PartialMatcher, options: ExpectWebdriverIO.StringOptions = {}) {
88
return toHaveAttributeAndValueFn.call(this, el, 'class', className, {
99
...options,
1010
containing: true

src/matchers/element/toHaveComputedLabel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
async function condition(
1212
el: WebdriverIO.Element,
13-
label: string | RegExp | Array<string | RegExp>,
13+
label: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>,
1414
options: ExpectWebdriverIO.HTMLOptions
1515
) {
1616
const actualLabel = await el.getComputedLabel()
@@ -22,7 +22,7 @@ async function condition(
2222

2323
export async function toHaveComputedLabel(
2424
received: WebdriverIO.Element | WebdriverIO.ElementArray,
25-
label: string | RegExp | Array<string | RegExp>,
25+
label: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>,
2626
options: ExpectWebdriverIO.StringOptions = {}
2727
) {
2828
const isNot = this.isNot

src/matchers/element/toHaveComputedLabelContaining.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { toHaveComputedLabel } from './toHaveComputedLabel.js'
22

3-
export function toHaveComputedLabelContaining(el: WebdriverIO.Element, label: string | RegExp | Array<string | RegExp>, options: ExpectWebdriverIO.StringOptions = {}) {
3+
export function toHaveComputedLabelContaining(el: WebdriverIO.Element, label: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>, options: ExpectWebdriverIO.StringOptions = {}) {
44
return toHaveComputedLabel.call(this, el, label, {
55
...options,
66
containing: true

src/matchers/element/toHaveComputedRole.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010

1111
async function condition(
1212
el: WebdriverIO.Element,
13-
role: string | RegExp | Array<string | RegExp>,
13+
role: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>,
1414
options: ExpectWebdriverIO.HTMLOptions
1515
) {
1616
const actualRole = await el.getComputedRole()
@@ -22,7 +22,7 @@ async function condition(
2222

2323
export async function toHaveComputedRole(
2424
received: WebdriverIO.Element | WebdriverIO.ElementArray,
25-
role: string | RegExp | Array<string | RegExp>,
25+
role: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>,
2626
options: ExpectWebdriverIO.StringOptions = {}
2727
) {
2828
const isNot = this.isNot

src/matchers/element/toHaveComputedRoleContaining.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { toHaveComputedRole } from './toHaveComputedRole.js'
22

3-
export function toHaveComputedRoleContaining(el: WebdriverIO.Element, role: string | RegExp | Array<string | RegExp>, options: ExpectWebdriverIO.StringOptions = {}) {
3+
export function toHaveComputedRoleContaining(el: WebdriverIO.Element, role: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>, options: ExpectWebdriverIO.StringOptions = {}) {
44
return toHaveComputedRole.call(this, el, role, {
55
...options,
66
containing: true

src/matchers/element/toHaveElementProperty.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function condition(
3636
export async function toHaveElementProperty(
3737
received: WebdriverIO.Element | WebdriverIO.ElementArray,
3838
property: string,
39-
value?: string | RegExp,
39+
value?: string | RegExp | ExpectWebdriverIO.PartialMatcher,
4040
options: ExpectWebdriverIO.StringOptions = {}
4141
) {
4242
const isNot = this.isNot

0 commit comments

Comments
 (0)