Unverified Commit ca1b6184 authored by Leah's avatar Leah Committed by GitHub

chore: update test template to use `nextTestSetup` (#62154)

### Why?

Less indentation and allows for IDE integration.



Closes PACK-2523
parent cbdd1d26
import { createNextDescribe } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
createNextDescribe( describe('{{name}}', () => {
'{{name}}', const { next } = nextTestSetup({
{
files: __dirname, files: __dirname,
}, })
({ next }) => {
// Recommended for tests that check HTML. Cheerio is a HTML parser that has a jQuery like API.
it('should work using cheerio', async () => {
const $ = await next.render$('/')
expect($('p').text()).toBe('hello world')
})
// Recommended for tests that need a full browser // Recommended for tests that check HTML. Cheerio is a HTML parser that has a jQuery like API.
it('should work using browser', async () => { it('should work using cheerio', async () => {
const browser = await next.browser('/') const $ = await next.render$('/')
expect(await browser.elementByCss('p').text()).toBe('hello world') expect($('p').text()).toBe('hello world')
}) })
// In case you need the full HTML. Can also use $.html() with cheerio. // Recommended for tests that need a full browser
it('should work with html', async () => { it('should work using browser', async () => {
const html = await next.render('/') const browser = await next.browser('/')
expect(html).toContain('hello world') expect(await browser.elementByCss('p').text()).toBe('hello world')
}) })
// In case you need to test the response object // In case you need the full HTML. Can also use $.html() with cheerio.
it('should work with fetch', async () => { it('should work with html', async () => {
const res = await next.fetch('/') const html = await next.render('/')
const html = await res.text() expect(html).toContain('hello world')
expect(html).toContain('hello world') })
})
} // In case you need to test the response object
) it('should work with fetch', async () => {
const res = await next.fetch('/')
const html = await res.text()
expect(html).toContain('hello world')
})
})
import { createNextDescribe } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
createNextDescribe( describe('nextTestSetup', () => {
'createNextDescribe', const { next } = nextTestSetup({
{
files: __dirname, files: __dirname,
}, })
({ next }) => {
it('should work', async () => { it('should work', async () => {
const res = await next.fetch('/') const res = await next.fetch('/')
expect(await res.text()).toContain('Hello World') expect(await res.text()).toContain('Hello World')
}) })
} })
)
...@@ -6394,7 +6394,7 @@ ...@@ -6394,7 +6394,7 @@
"runtimeError": false "runtimeError": false
}, },
"test/e2e/test-utils-tests/basic/basic.test.ts": { "test/e2e/test-utils-tests/basic/basic.test.ts": {
"passed": ["createNextDescribe should work"], "passed": ["nextTestSetup should work"],
"failed": [], "failed": [],
"pending": [], "pending": [],
"flakey": [], "flakey": [],
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment