/
spa-base.browser.test.js
71 lines (52 loc) · 1.87 KB
/
spa-base.browser.test.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Browser from '../utils/browser'
import { loadFixture, getPort, Nuxt } from '../utils'
let port
const browser = new Browser()
const url = route => 'http://localhost:' + port + route
let nuxt = null
let page = null
describe('spa router base browser', () => {
beforeAll(async () => {
const config = await loadFixture('spa-base')
nuxt = new Nuxt(config)
await nuxt.ready()
port = await getPort()
await nuxt.server.listen(port, 'localhost')
await browser.start({
// slowMo: 50,
// headless: false
})
})
test('Open /app (router base)', async () => {
page = await browser.page(url('/app'))
expect(await page.evaluate(() => location.href)).toBe(url('/app'))
expect(await page.html()).not.toContain('This page could not be found')
expect(await page.evaluate(() => {
const headings = document.evaluate("//div[text()='Hello SPA!']", document, null, XPathResult.ANY_TYPE, null)
return headings.iterateNext()
})).not.toBe(null)
})
test('Open /app/ (router base with trailing slash)', async () => {
page = await browser.page(url('/app/'))
expect(await page.evaluate(() => location.href)).toBe(url('/app/'))
expect(await page.html()).not.toContain('This page could not be found')
})
test('Open /app/mounted', async () => {
page = await browser.page(url('/app/mounted'))
expect(await page.$text('h1')).toMatch('Test: updated')
})
test('/app/unknown', async () => {
page = await browser.page(url('/app/unknown'))
expect(await page.evaluate(() => location.href)).toBe(url('/app/unknown'))
expect(await page.html()).toContain('This page could not be found')
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
})
// Stop browser
afterAll(async () => {
await page.close()
await browser.close()
})
})