fix: support regexp flags with locator.withText() (#10779)
This commit is contained in:
		
							parent
							
								
									a08a41f6c9
								
							
						
					
					
						commit
						fdb633dc8b
					
				|  | @ -99,9 +99,9 @@ export class Locator implements api.Locator { | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   withText(text: string | RegExp): Locator { |   withText(text: string | RegExp): Locator { | ||||||
|     const matcher = isRegExp(text) ? 'text-matches' : 'has-text'; |     if (isRegExp(text)) | ||||||
|     const source = escapeWithQuotes(isRegExp(text) ? text.source : text, '"'); |       return new Locator(this._frame, this._selector + ` >> :scope:text-matches(${escapeWithQuotes(text.source, '"')}, "${text.flags}")`); | ||||||
|     return new Locator(this._frame, this._selector + ` >> :scope:${matcher}(${source})`); |     return new Locator(this._frame, this._selector + ` >> :scope:has-text(${escapeWithQuotes(text, '"')})`); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   frameLocator(selector: string): FrameLocator { |   frameLocator(selector: string): FrameLocator { | ||||||
|  |  | ||||||
|  | @ -84,3 +84,8 @@ it('should filter by regex with quotes', async ({ page }) => { | ||||||
|   await page.setContent(`<div>Hello "world"</div><div>Hello world</div>`); |   await page.setContent(`<div>Hello "world"</div><div>Hello world</div>`); | ||||||
|   await expect(page.locator('div').withText(/Hello "world"/)).toHaveText('Hello "world"'); |   await expect(page.locator('div').withText(/Hello "world"/)).toHaveText('Hello "world"'); | ||||||
| }); | }); | ||||||
|  | 
 | ||||||
|  | it('should filter by regex and regexp flags', async ({ page }) => { | ||||||
|  |   await page.setContent(`<div>Hello "world"</div><div>Hello world</div>`); | ||||||
|  |   await expect(page.locator('div').withText(/hElLo "world"/i)).toHaveText('Hello "world"'); | ||||||
|  | }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue