( browser: Playwright, queryValue: string, expected: RegExp | string | string[] | undefined | null, queryKey: string = 'property', tag: string = 'meta', domAttributeField: string = 'content' )
| 1761 | browser.elementByCss('title', { state: 'attached' }).text() |
| 1762 | |
| 1763 | async function checkMeta( |
| 1764 | browser: Playwright, |
| 1765 | queryValue: string, |
| 1766 | expected: RegExp | string | string[] | undefined | null, |
| 1767 | queryKey: string = 'property', |
| 1768 | tag: string = 'meta', |
| 1769 | domAttributeField: string = 'content' |
| 1770 | ) { |
| 1771 | const values = await browser.eval<(string | null)[]>( |
| 1772 | `[...document.querySelectorAll('${tag}[${queryKey}="${queryValue}"]')].map((el) => el.getAttribute("${domAttributeField}"))` |
| 1773 | ) |
| 1774 | if (expected instanceof RegExp) { |
| 1775 | expect(values[0]).toMatch(expected) |
| 1776 | } else { |
| 1777 | if (Array.isArray(expected)) { |
| 1778 | expect(values).toEqual(expected) |
| 1779 | } else { |
| 1780 | // If expected is undefined, then it should not exist. |
| 1781 | // Otherwise, it should exist in the matched values. |
| 1782 | if (expected === undefined) { |
| 1783 | expect(values).not.toContain(undefined) |
| 1784 | } else { |
| 1785 | expect(values).toContain(expected) |
| 1786 | } |
| 1787 | } |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | export function createDomMatcher(browser: Playwright) { |
| 1792 | /** |
no test coverage detected