PactDOCS

OPERATE / TEST

Test consent behavior

Test observable execution—not whether a banner happens to look present.
01

Prove optional code did not execute

consent.spec.ts
typescript
test('marketing waits for consent', async ({ page }) => {
  const marketing = []
  page.on('request', request => {
    if (request.url().includes('/marketing.js')) marketing.push(request.url())
  })

  await page.goto('/?region=EU')
  await page.evaluate(() => window.pact.ready)
  expect(marketing).toHaveLength(0)
})
02

Prove the quiet path makes no request

consent.spec.ts
typescript
test('quiet path lazy-loads preferences', async ({ page }) => {
  const core = []
  page.on('request', request => {
    if (new URL(request.url()).pathname === '/pact.js') core.push(request.url())
  })

  await page.goto('/?region=TX')
  expect(core).toHaveLength(0)
  await page.getByRole('button', { name: 'Privacy choices' }).click()
  expect(core).toHaveLength(1)
})
03

Minimum acceptance matrix

  • Bootstrap precedes every optional tag
  • GPC and stored rejection block before execution
  • Quiet path makes zero initial core requests
  • Purpose gates react to approval and withdrawal
  • Runtime hostname and version match
  • CLS remains 0.00 and Pact is never LCP
NEXTVerify production