Testing in a browser

Set up testing for browser

Under the hood, Nuxt test utils uses playwright to carry out browser testing.

These helper methods require that you pass { browser: true } as an option to setupTest (more info).

createPage

You can initiate a browser session for a given page with createPage.

You can find out more about the properties and methods on the page object in the playwright documentation.

Example

import { createPage, setupTest } from '@nuxt/test-utils'

describe('browser', () => {
  setupTest({ browser: true })

  it('renders the index page', async () => {
    const page = await createPage('/')
    const html = await page.innerHTML('body')

    expect(html).toContain('Something')
  })
})