| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Copyright (c) Microsoft Corporation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  | import { test, expect, stripAnsi } from './playwright-test-fixtures'; | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  | test('should support toHaveText w/ regex', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-09-14 19:24:29 -07:00
										 |  |  |         await page.setContent('<div id=node>Text   content</div>'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toHaveText(/Text/); | 
					
						
							| 
									
										
										
										
											2021-09-14 19:24:29 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // Should not normalize whitespace.
 | 
					
						
							|  |  |  |         await expect(locator).toHaveText(/Text   content/); | 
					
						
							| 
									
										
										
										
											2022-06-02 05:52:53 -07:00
										 |  |  |         // Should respect ignoreCase.
 | 
					
						
							|  |  |  |         await expect(locator).toHaveText(/text   content/, { ignoreCase: true }); | 
					
						
							|  |  |  |         // Should override regex flag with ignoreCase.
 | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText(/text   content/i, { ignoreCase: false }); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('fail', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toHaveText(/Text 2/, { timeout: 100 }); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   const output = stripAnsi(result.output); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |   expect(output).toContain('Error: expect(received).toHaveText(expected)'); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |   expect(output).toContain('Expected pattern: /Text 2/'); | 
					
						
							|  |  |  |   expect(output).toContain('Received string:  "Text content"'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |   expect(output).toContain('expect(locator).toHaveText'); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-27 11:14:35 -07:00
										 |  |  | test('should support toContainText w/ regex', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text   content</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toContainText(/ex/); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Should not normalize whitespace.
 | 
					
						
							|  |  |  |         await expect(locator).toContainText(/ext   cont/); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('fail', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toContainText(/ex2/, { timeout: 100 }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   const output = stripAnsi(result.output); | 
					
						
							| 
									
										
										
										
											2021-09-27 11:14:35 -07:00
										 |  |  |   expect(output).toContain('Error: expect(received).toContainText(expected)'); | 
					
						
							|  |  |  |   expect(output).toContain('Expected pattern: /ex2/'); | 
					
						
							|  |  |  |   expect(output).toContain('Received string:  "Text content"'); | 
					
						
							|  |  |  |   expect(output).toContain('expect(locator).toContainText'); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  | test('should support toHaveText w/ text', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-09-14 19:24:29 -07:00
										 |  |  |         await page.setContent('<div id=node><span></span>Text \\ncontent     </div>'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |         const locator = page.locator('#node'); | 
					
						
							| 
									
										
										
										
											2021-09-14 19:24:29 -07:00
										 |  |  |         // Should normalize whitespace.
 | 
					
						
							|  |  |  |         await expect(locator).toHaveText('Text                        content'); | 
					
						
							| 
									
										
										
										
											2021-12-01 09:21:21 -08:00
										 |  |  |         // Should normalize zero width whitespace.
 | 
					
						
							|  |  |  |         await expect(locator).toHaveText('T\u200be\u200bx\u200bt content'); | 
					
						
							| 
									
										
										
										
											2022-06-02 05:52:53 -07:00
										 |  |  |         // Should support ignoreCase.
 | 
					
						
							|  |  |  |         await expect(locator).toHaveText('text CONTENT', { ignoreCase: true }); | 
					
						
							|  |  |  |         // Should support falsy ignoreCase.
 | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText('TEXT', { ignoreCase: false }); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass contain', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toContainText('Text'); | 
					
						
							| 
									
										
										
										
											2021-09-14 19:24:29 -07:00
										 |  |  |         // Should normalize whitespace.
 | 
					
						
							| 
									
										
										
										
											2021-09-27 11:14:35 -07:00
										 |  |  |         await expect(locator).toContainText('   ext        cont\\n  '); | 
					
						
							| 
									
										
										
										
											2022-06-02 05:52:53 -07:00
										 |  |  |         // Should support ignoreCase.
 | 
					
						
							|  |  |  |         await expect(locator).toContainText('EXT', { ignoreCase: true }); | 
					
						
							|  |  |  |         // Should support falsy ignoreCase.
 | 
					
						
							|  |  |  |         await expect(locator).not.toContainText('TEXT', { ignoreCase: false }); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('fail', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toHaveText('Text', { timeout: 100 }); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   const output = stripAnsi(result.output); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |   expect(output).toContain('Error: expect(received).toHaveText(expected)'); | 
					
						
							|  |  |  |   expect(output).toContain('Expected string: "Text"'); | 
					
						
							|  |  |  |   expect(output).toContain('Received string: "Text content"'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |   expect(output).toContain('expect(locator).toHaveText'); | 
					
						
							|  |  |  |   expect(result.passed).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 16:46:46 -07:00
										 |  |  | test('should support toHaveText w/ not', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText('Text2'); | 
					
						
							| 
									
										
										
										
											2022-06-02 05:52:53 -07:00
										 |  |  |         // Should be case-sensitive by default.
 | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText('TEXT'); | 
					
						
							| 
									
										
										
										
											2021-09-23 16:46:46 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('fail', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText('Text content', { timeout: 100 }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   const output = stripAnsi(result.output); | 
					
						
							| 
									
										
										
										
											2021-09-23 16:46:46 -07:00
										 |  |  |   expect(output).toContain('Error: expect(received).not.toHaveText(expected)'); | 
					
						
							|  |  |  |   expect(output).toContain('Expected string: not "Text content"'); | 
					
						
							|  |  |  |   expect(output).toContain('Received string: "Text content'); | 
					
						
							|  |  |  |   expect(output).toContain('expect(locator).not.toHaveText'); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-29 07:33:19 -07:00
										 |  |  | test('should support toHaveText w/ array', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2021-09-14 19:24:29 -07:00
										 |  |  |         await page.setContent('<div>Text    \\n1</div><div>Text   2a</div>'); | 
					
						
							| 
									
										
										
										
											2021-07-29 07:33:19 -07:00
										 |  |  |         const locator = page.locator('div'); | 
					
						
							| 
									
										
										
										
											2021-09-14 19:24:29 -07:00
										 |  |  |         // Should only normalize whitespace in the first item.
 | 
					
						
							|  |  |  |         await expect(locator).toHaveText(['Text  1', /Text   \\d+a/]); | 
					
						
							| 
									
										
										
										
											2022-06-02 05:52:53 -07:00
										 |  |  |         // Should support ignoreCase.
 | 
					
						
							|  |  |  |         await expect(locator).toHaveText(['tEXT 1', 'TExt 2A'], { ignoreCase: true }); | 
					
						
							| 
									
										
										
										
											2021-07-29 07:33:19 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-11 13:01:09 -08:00
										 |  |  |       test('pass lazy', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=div></div>'); | 
					
						
							|  |  |  |         const locator = page.locator('p'); | 
					
						
							|  |  |  |         setTimeout(() => { | 
					
						
							|  |  |  |           page.evaluate(() => { | 
					
						
							|  |  |  |             div.innerHTML = "<p>Text 1</p><p>Text 2</p>"; | 
					
						
							|  |  |  |           }).catch(() => {}); | 
					
						
							|  |  |  |         }, 500); | 
					
						
							|  |  |  |         await expect(locator).toHaveText(['Text 1', 'Text 2']); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass empty', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div></div>'); | 
					
						
							|  |  |  |         const locator = page.locator('p'); | 
					
						
							|  |  |  |         await expect(locator).toHaveText([]); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass not empty', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div><p>Test</p></div>'); | 
					
						
							|  |  |  |         const locator = page.locator('p'); | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText([]); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass on empty', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div></div>'); | 
					
						
							|  |  |  |         const locator = page.locator('p'); | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText(['Test']); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-13 08:56:57 -07:00
										 |  |  |       test('fail on not+empty', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div></div>'); | 
					
						
							|  |  |  |         const locator = page.locator('p'); | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText([], { timeout: 1000 }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-11 13:01:09 -08:00
										 |  |  |       test('pass eventually empty', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=div><p>Text</p></div>'); | 
					
						
							|  |  |  |         const locator = page.locator('p'); | 
					
						
							|  |  |  |         setTimeout(() => { | 
					
						
							|  |  |  |           page.evaluate(() => div.innerHTML = "").catch(() => {}); | 
					
						
							|  |  |  |         }, 500); | 
					
						
							|  |  |  |         await expect(locator).not.toHaveText([]); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-29 07:33:19 -07:00
										 |  |  |       test('fail', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div>Text 1</div><div>Text 3</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('div'); | 
					
						
							| 
									
										
										
										
											2021-09-27 11:14:35 -07:00
										 |  |  |         await expect(locator).toHaveText(['Text 1', /Text \\d/, 'Extra'], { timeout: 1000 }); | 
					
						
							| 
									
										
										
										
											2021-07-29 07:33:19 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   const output = stripAnsi(result.output); | 
					
						
							| 
									
										
										
										
											2021-07-29 07:33:19 -07:00
										 |  |  |   expect(output).toContain('Error: expect(received).toHaveText(expected) // deep equality'); | 
					
						
							|  |  |  |   expect(output).toContain('await expect(locator).toHaveText'); | 
					
						
							| 
									
										
										
										
											2021-09-27 11:14:35 -07:00
										 |  |  |   expect(output).toContain('-   "Extra"'); | 
					
						
							|  |  |  |   expect(output).toContain('waiting for selector "div"'); | 
					
						
							|  |  |  |   expect(output).toContain('selector resolved to 2 elements'); | 
					
						
							| 
									
										
										
										
											2021-10-11 13:01:09 -08:00
										 |  |  |   expect(result.passed).toBe(6); | 
					
						
							| 
									
										
										
										
											2021-10-13 08:56:57 -07:00
										 |  |  |   expect(result.failed).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-09-27 11:14:35 -07:00
										 |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should support toContainText w/ array', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div>Text \\n1</div><div>Text2</div><div>Text3</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('div'); | 
					
						
							|  |  |  |         await expect(locator).toContainText(['ext     1', /ext3/]); | 
					
						
							| 
									
										
										
										
											2022-06-02 05:52:53 -07:00
										 |  |  |         // Should support ignoreCase.
 | 
					
						
							|  |  |  |         await expect(locator).toContainText(['EXT 1', 'eXt3'], { ignoreCase: true }); | 
					
						
							| 
									
										
										
										
											2021-09-27 11:14:35 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('fail', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div>Text 1</div><div>Text 3</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('div'); | 
					
						
							|  |  |  |         await expect(locator).toContainText(['Text 2'], { timeout: 1000 }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   const output = stripAnsi(result.output); | 
					
						
							| 
									
										
										
										
											2021-09-27 11:14:35 -07:00
										 |  |  |   expect(output).toContain('Error: expect(received).toContainText(expected)'); | 
					
						
							|  |  |  |   expect(output).toContain('await expect(locator).toContainText'); | 
					
						
							|  |  |  |   expect(output).toContain('-   "Text 2"'); | 
					
						
							| 
									
										
										
										
											2021-07-29 07:33:19 -07:00
										 |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  | test('should support toHaveText eventually', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass eventually', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |         const locator = page.locator('#node'); | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |         await Promise.all([ | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |           expect(locator).toHaveText(/Text 2/), | 
					
						
							|  |  |  |           page.waitForTimeout(1000).then(() => locator.evaluate(element => element.textContent = 'Text 2 content')), | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |         ]); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.failed).toBe(0); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  | test('should support toHaveText with innerText', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							| 
									
										
										
										
											2022-04-27 15:48:38 -07:00
										 |  |  |         await page.setContent('<div id=node>Text <span hidden>garbage</span> content</div>'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toHaveText('Text content', { useInnerText: true }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-06 16:58:42 -07:00
										 |  |  | test('should support toHaveAttribute', async ({ runInlineTest }) => { | 
					
						
							| 
									
										
										
										
											2021-07-27 20:26:12 -07:00
										 |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |         const locator = page.locator('#node'); | 
					
						
							| 
									
										
										
										
											2021-08-06 16:58:42 -07:00
										 |  |  |         await expect(locator).toHaveAttribute('id', 'node'); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should support toHaveCSS', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node style="color: rgb(255, 0, 0)">Text content</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toHaveCSS('color', 'rgb(255, 0, 0)'); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2022-03-12 18:32:40 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       test('pass with custom css properties', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node style="--custom-color-property:#FF00FF;">Text content</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toHaveCSS('--custom-color-property', '#FF00FF'); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2022-03-12 18:32:40 +01:00
										 |  |  |   expect(result.passed).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should support toHaveId', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await expect(locator).toHaveId('node'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should support toHaveValue', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<input id=node></input>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await locator.fill('Text content'); | 
					
						
							|  |  |  |         await expect(locator).toHaveValue('Text content'); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-12-02 10:31:06 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       test('pass on label', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<label><input></input></label>'); | 
					
						
							|  |  |  |         await page.locator('label input').fill('Text content'); | 
					
						
							|  |  |  |         await expect(page.locator('label')).toHaveValue('Text content'); | 
					
						
							|  |  |  |       }); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							| 
									
										
										
										
											2021-12-02 10:31:06 -08:00
										 |  |  |   expect(result.passed).toBe(2); | 
					
						
							| 
									
										
										
										
											2021-07-28 12:07:11 -07:00
										 |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-07-30 13:12:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 16:46:46 -07:00
										 |  |  | test('should support toHaveValue regex', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<input id=node></input>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await locator.fill('Text content'); | 
					
						
							|  |  |  |         await expect(locator).toHaveValue(/Text/); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.passed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should support toHaveValue failing', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('pass', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<input id=node></input>'); | 
					
						
							|  |  |  |         const locator = page.locator('#node'); | 
					
						
							|  |  |  |         await locator.fill('Text content'); | 
					
						
							|  |  |  |         await expect(locator).toHaveValue(/Text2/, { timeout: 1000 }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.output).toContain('"Text content"'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-02 16:01:34 -04:00
										 |  |  | test.describe('should support toHaveValues with multi-select', () => { | 
					
						
							| 
									
										
										
										
											2022-06-02 12:10:28 -04:00
										 |  |  |   test('works with text', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							|  |  |  |       'a.test.ts': `
 | 
					
						
							|  |  |  |         const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass', async ({ page }) => { | 
					
						
							|  |  |  |           await page.setContent(\`
 | 
					
						
							|  |  |  |             <select multiple> | 
					
						
							|  |  |  |               <option value="R">Red</option> | 
					
						
							|  |  |  |               <option value="G">Green</option> | 
					
						
							|  |  |  |               <option value="B">Blue</option> | 
					
						
							|  |  |  |             </select> | 
					
						
							|  |  |  |           \`);
 | 
					
						
							|  |  |  |           const locator = page.locator('select'); | 
					
						
							|  |  |  |           await locator.selectOption(['R', 'G']); | 
					
						
							| 
									
										
										
										
											2022-06-02 16:01:34 -04:00
										 |  |  |           await expect(locator).toHaveValues(['R', 'G']); | 
					
						
							| 
									
										
										
										
											2022-06-02 12:10:28 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test('follows labels', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							|  |  |  |       'a.test.ts': `
 | 
					
						
							|  |  |  |         const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass', async ({ page }) => { | 
					
						
							|  |  |  |           await page.setContent(\`
 | 
					
						
							|  |  |  |             <label for="colors">Pick a Color</label> | 
					
						
							|  |  |  |             <select id="colors" multiple> | 
					
						
							|  |  |  |               <option value="R">Red</option> | 
					
						
							|  |  |  |               <option value="G">Green</option> | 
					
						
							|  |  |  |               <option value="B">Blue</option> | 
					
						
							|  |  |  |             </select> | 
					
						
							|  |  |  |           \`);
 | 
					
						
							|  |  |  |           const locator = page.locator('text=Pick a Color'); | 
					
						
							|  |  |  |           await locator.selectOption(['R', 'G']); | 
					
						
							| 
									
										
										
										
											2022-06-02 16:01:34 -04:00
										 |  |  |           await expect(locator).toHaveValues(['R', 'G']); | 
					
						
							| 
									
										
										
										
											2022-06-02 12:10:28 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test('exact match with text', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							|  |  |  |       'a.test.ts': `
 | 
					
						
							|  |  |  |         const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass', async ({ page }) => { | 
					
						
							|  |  |  |           await page.setContent(\`
 | 
					
						
							|  |  |  |             <select multiple> | 
					
						
							|  |  |  |               <option value="RR">Red</option> | 
					
						
							|  |  |  |               <option value="GG">Green</option> | 
					
						
							|  |  |  |             </select> | 
					
						
							|  |  |  |           \`);
 | 
					
						
							|  |  |  |           const locator = page.locator('select'); | 
					
						
							|  |  |  |           await locator.selectOption(['RR', 'GG']); | 
					
						
							| 
									
										
										
										
											2022-06-02 16:01:34 -04:00
										 |  |  |           await expect(locator).toHaveValues(['R', 'G']); | 
					
						
							| 
									
										
										
										
											2022-06-02 12:10:28 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.passed).toBe(0); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |     expect(stripAnsi(result.output)).toContain(`
 | 
					
						
							|  |  |  |     - Expected  - 2 | 
					
						
							|  |  |  |     + Received  + 2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       Array [ | 
					
						
							|  |  |  |     -   "R", | 
					
						
							|  |  |  |     -   "G", | 
					
						
							|  |  |  |     +   "RR", | 
					
						
							|  |  |  |     +   "GG", | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  | `);
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test('works with regex', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							|  |  |  |       'a.test.ts': `
 | 
					
						
							|  |  |  |         const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass', async ({ page }) => { | 
					
						
							|  |  |  |           await page.setContent(\`
 | 
					
						
							|  |  |  |             <select multiple> | 
					
						
							|  |  |  |               <option value="R">Red</option> | 
					
						
							|  |  |  |               <option value="G">Green</option> | 
					
						
							|  |  |  |               <option value="B">Blue</option> | 
					
						
							|  |  |  |             </select> | 
					
						
							|  |  |  |           \`);
 | 
					
						
							|  |  |  |           const locator = page.locator('select'); | 
					
						
							|  |  |  |           await locator.selectOption(['R', 'G']); | 
					
						
							| 
									
										
										
										
											2022-06-02 16:01:34 -04:00
										 |  |  |           await expect(locator).toHaveValues([/R/, /G/]); | 
					
						
							| 
									
										
										
										
											2022-06-02 12:10:28 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.passed).toBe(1); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(0); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test('fails when items not selected', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							|  |  |  |       'a.test.ts': `
 | 
					
						
							|  |  |  |         const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass', async ({ page }) => { | 
					
						
							|  |  |  |           await page.setContent(\`
 | 
					
						
							|  |  |  |             <select multiple> | 
					
						
							|  |  |  |               <option value="R">Red</option> | 
					
						
							|  |  |  |               <option value="G">Green</option> | 
					
						
							|  |  |  |               <option value="B">Blue</option> | 
					
						
							|  |  |  |             </select> | 
					
						
							|  |  |  |           \`);
 | 
					
						
							|  |  |  |           const locator = page.locator('select'); | 
					
						
							|  |  |  |           await locator.selectOption(['B']); | 
					
						
							| 
									
										
										
										
											2022-06-02 16:01:34 -04:00
										 |  |  |           await expect(locator).toHaveValues([/R/, /G/]); | 
					
						
							| 
									
										
										
										
											2022-06-02 12:10:28 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.passed).toBe(0); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |     expect(stripAnsi(result.output)).toContain(`
 | 
					
						
							|  |  |  |     - Expected  - 2 | 
					
						
							|  |  |  |     + Received  + 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       Array [ | 
					
						
							|  |  |  |     -   /R/, | 
					
						
							|  |  |  |     -   /G/, | 
					
						
							|  |  |  |     +   "B", | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  | `);
 | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test('fails when multiple not specified', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							|  |  |  |       'a.test.ts': `
 | 
					
						
							|  |  |  |         const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass', async ({ page }) => { | 
					
						
							|  |  |  |           await page.setContent(\`
 | 
					
						
							|  |  |  |             <select> | 
					
						
							|  |  |  |               <option value="R">Red</option> | 
					
						
							|  |  |  |               <option value="G">Green</option> | 
					
						
							|  |  |  |               <option value="B">Blue</option> | 
					
						
							|  |  |  |             </select> | 
					
						
							|  |  |  |           \`);
 | 
					
						
							|  |  |  |           const locator = page.locator('select'); | 
					
						
							|  |  |  |           await locator.selectOption(['B']); | 
					
						
							| 
									
										
										
										
											2022-06-02 16:01:34 -04:00
										 |  |  |           await expect(locator).toHaveValues([/R/, /G/]); | 
					
						
							| 
									
										
										
										
											2022-06-02 12:10:28 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.passed).toBe(0); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |     expect(result.output).toContain('Not a select element with a multiple attribute'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test('fails when not a select element', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |     const result = await runInlineTest({ | 
					
						
							|  |  |  |       'a.test.ts': `
 | 
					
						
							|  |  |  |         const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         test('pass', async ({ page }) => { | 
					
						
							|  |  |  |           await page.setContent(\`
 | 
					
						
							|  |  |  |             <input value="foo" /> | 
					
						
							|  |  |  |           \`);
 | 
					
						
							|  |  |  |           const locator = page.locator('input'); | 
					
						
							| 
									
										
										
										
											2022-06-02 16:01:34 -04:00
										 |  |  |           await expect(locator).toHaveValues([/R/, /G/]); | 
					
						
							| 
									
										
										
										
											2022-06-02 12:10:28 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  |         `,
 | 
					
						
							|  |  |  |     }, { workers: 1 }); | 
					
						
							|  |  |  |     expect(result.passed).toBe(0); | 
					
						
							|  |  |  |     expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |     expect(result.output).toContain('Not a select element with a multiple attribute'); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-30 13:12:49 -07:00
										 |  |  | test('should print expected/received before timeout', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('times out waiting for text', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							|  |  |  |         await expect(page.locator('#node')).toHaveText('Text 2'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1, timeout: 2000 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.output).toContain('Timeout of 2000ms exceeded.'); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   expect(stripAnsi(result.output)).toContain('Expected string: "Text 2"'); | 
					
						
							|  |  |  |   expect(stripAnsi(result.output)).toContain('Received string: "Text content"'); | 
					
						
							| 
									
										
										
										
											2021-07-30 13:12:49 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-09-15 21:28:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('should print nice error for toHaveText', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('fail', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							|  |  |  |         await expect(page.locator('no-such-thing')).toHaveText('Text'); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1, timeout: 2000 }); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   const output = stripAnsi(result.output); | 
					
						
							| 
									
										
										
										
											2021-09-15 21:28:36 -07:00
										 |  |  |   expect(output).toContain('Pending operations:'); | 
					
						
							|  |  |  |   expect(output).toContain('Error: expect(received).toHaveText(expected)'); | 
					
						
							|  |  |  |   expect(output).toContain('Expected string: "Text"'); | 
					
						
							| 
									
										
										
										
											2021-09-24 18:55:45 -07:00
										 |  |  |   expect(output).toContain('Received string: ""'); | 
					
						
							|  |  |  |   expect(output).toContain('waiting for selector "no-such-thing"'); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should print expected/received on Ctrl+C', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   test.skip(process.platform === 'win32', 'No sending SIGINT on Windows'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('times out waiting for text', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div id=node>Text content</div>'); | 
					
						
							|  |  |  |         const promise = expect(page.locator('#node')).toHaveText('Text 2'); | 
					
						
							|  |  |  |         await new Promise(f => setTimeout(f, 500)); | 
					
						
							|  |  |  |         console.log('\\n%%SEND-SIGINT%%'); | 
					
						
							|  |  |  |         await promise; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }, {}, { sendSIGINTAfter: 1 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(130); | 
					
						
							|  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |   expect(result.skipped).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   expect(stripAnsi(result.output)).toContain('Expected string: "Text 2"'); | 
					
						
							|  |  |  |   expect(stripAnsi(result.output)).toContain('Received string: "Text content"'); | 
					
						
							| 
									
										
										
										
											2021-09-24 18:55:45 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('should support not.toHaveText when selector does not match', async ({ runInlineTest }) => { | 
					
						
							|  |  |  |   const result = await runInlineTest({ | 
					
						
							|  |  |  |     'a.test.ts': `
 | 
					
						
							|  |  |  |       const { test } = pwt; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       test('fails', async ({ page }) => { | 
					
						
							|  |  |  |         await page.setContent('<div>hello</div>'); | 
					
						
							|  |  |  |         await expect(page.locator('span')).not.toHaveText('hello', { timeout: 1000 }); | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       `,
 | 
					
						
							|  |  |  |   }, { workers: 1 }); | 
					
						
							|  |  |  |   expect(result.exitCode).toBe(1); | 
					
						
							|  |  |  |   expect(result.passed).toBe(0); | 
					
						
							|  |  |  |   expect(result.failed).toBe(1); | 
					
						
							| 
									
										
										
										
											2022-01-31 18:14:59 -07:00
										 |  |  |   const output = stripAnsi(result.output); | 
					
						
							| 
									
										
										
										
											2021-09-24 18:55:45 -07:00
										 |  |  |   expect(output).toContain('Expected string: not "hello"'); | 
					
						
							|  |  |  |   expect(output).toContain('Received string: ""'); | 
					
						
							|  |  |  |   expect(output).toContain('waiting for selector "span"'); | 
					
						
							| 
									
										
										
										
											2021-09-15 21:28:36 -07:00
										 |  |  | }); |