2022-12-19 20:08:50 +01:00
|
|
|
import { createNextDescribe } from 'e2e-utils'
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2022-12-19 20:08:50 +01:00
|
|
|
createNextDescribe(
|
|
|
|
'{{name}}',
|
|
|
|
{
|
|
|
|
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
|
|
|
|
it('should work using browser', async () => {
|
|
|
|
const browser = await next.browser('/')
|
2022-12-20 01:31:28 +01:00
|
|
|
expect(await browser.elementByCss('p').text()).toBe('hello world')
|
2022-12-19 20:08:50 +01:00
|
|
|
})
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2022-12-19 20:08:50 +01:00
|
|
|
// In case you need the full HTML. Can also use $.html() with cheerio.
|
|
|
|
it('should work with html', async () => {
|
|
|
|
const html = await next.render('/')
|
|
|
|
expect(html).toContain('hello world')
|
2021-09-13 14:36:25 +02:00
|
|
|
})
|
|
|
|
|
2022-12-19 20:08:50 +01:00
|
|
|
// 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')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|