/
index.test.ts
45 lines (39 loc) · 1.22 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { createNext, FileRef } from 'e2e-utils'
import { renderViaHTTP } from 'next-test-utils'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
import { NextInstance } from 'test/lib/next-modes/base'
import { join } from 'path'
describe('should set-up next', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
pages: new FileRef(join(__dirname, 'app/pages')),
components: new FileRef(join(__dirname, 'app/components')),
},
dependencies: {
react: '17',
'react-dom': '17',
},
})
})
afterAll(() => next.destroy())
it('should have correct head tags in initial document', async () => {
const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html)
for (let i = 1; i < 5; i++) {
expect($(`meta[name="test-head-${i}"]`).attr()['content']).toBe('hello')
}
})
it('should have correct head tags after hydration', async () => {
const browser = await webdriver(next.url, '/')
for (let i = 1; i < 5; i++) {
expect(
await browser
.elementByCss(`meta[name="test-head-${i}"]`)
.getAttribute('content')
).toBe('hello')
}
})
})