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
0 commit comments