(page: Page, selector: string, expectedStack: string[])
| 1 | import { expect, type Page, type Locator } from '@playwright/test'; |
| 2 | |
| 3 | export async function testStack(page: Page, selector: string, expectedStack: string[]) { |
| 4 | const elements = page.locator(`${selector} > *`); |
| 5 | const count = await elements.count(); |
| 6 | |
| 7 | // Get the actual stack (tag names of child elements), filtering out non-components |
| 8 | const actualStack: string[] = []; |
| 9 | for (let i = 0; i < count; i++) { |
| 10 | const tagName = await elements.nth(i).evaluate(el => el.tagName.toLowerCase()); |
| 11 | // Filter out non-component elements like 'slot', 'div', etc. |
| 12 | if (tagName.includes('-') || tagName.startsWith('app-') || tagName.startsWith('ion-')) { |
| 13 | actualStack.push(tagName); |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | // Compare the actual stack with the expected stack |
| 18 | expect(actualStack).toEqual(expectedStack); |
| 19 | } |
| 20 | |
| 21 | export async function testLifeCycle(page: Page, selector: string, expectedCounts: Record<string, number>) { |
| 22 | await expect(page.locator(`${selector} #ngOnInit`)).toHaveText('1'); |
no test coverage detected