MCPcopy
hub / github.com/vercel/next.js / checkMeta

Function checkMeta

test/lib/next-test-utils.ts:1763–1789  ·  view source on GitHub ↗
(
  browser: Playwright,
  queryValue: string,
  expected: RegExp | string | string[] | undefined | null,
  queryKey: string = 'property',
  tag: string = 'meta',
  domAttributeField: string = 'content'
)

Source from the content-addressed store, hash-verified

1761 browser.elementByCss('title', { state: 'attached' }).text()
1762
1763async 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
1791export function createDomMatcher(browser: Playwright) {
1792 /**

Callers 3

createMultiDomMatcherFunction · 0.85
checkMetaNameContentPairFunction · 0.85
checkLinkFunction · 0.85

Calls 2

isArrayMethod · 0.80
expectFunction · 0.50

Tested by

no test coverage detected