-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathmodule.test.js
More file actions
75 lines (62 loc) · 2.17 KB
/
module.test.js
File metadata and controls
75 lines (62 loc) · 2.17 KB
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
72
73
74
75
const { Nuxt, Builder } = require('nuxt-edge')
const request = require('request-promise-native')
const config = require('./fixture/nuxt.config')
const url = path => `http://localhost:3000${path}`
const get = path => request(url(path))
describe('basic', () => {
let nuxt
beforeAll(async () => {
nuxt = new Nuxt(config)
await new Builder(nuxt).build()
await nuxt.listen(3000)
}, 60000)
afterAll(async () => {
await nuxt.close()
})
test('render', async () => {
const html = await get('/')
expect(html).toContain('This is the landing page')
})
test('normalQuery', async () => {
const html = await get('/normalQuery')
expect(html).toContain('Pilot')
})
test('asyncData', async () => {
const html = await get('/asyncData')
expect(html).toContain('Pilot')
})
test('mounted & smart query', async () => {
const window = await nuxt.renderAndGetWindow(url('/mounted'))
window.onNuxtReady(() => {
const html = window.document.body.innerHTML
expect(html).toContain('cjw1jhoxi1f4g0112ayaq3pyz')
})
})
test('onLogin', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
const token = 'this-is-the-token'
window.$nuxt.$apolloHelpers.onLogin(token)
expect(window.$nuxt.$apolloHelpers.getToken()).toContain(token)
})
test('onLogout', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
const token = 'this-is-the-token'
window.$nuxt.$apolloHelpers.onLogin(token)
window.$nuxt.$apolloHelpers.onLogout()
expect(window.$nuxt.$apolloHelpers.getToken()).toBeUndefined()
})
test('repeat onLogin onLogout', async () => {
const window = await nuxt.renderAndGetWindow(url('/'))
const token = 'this-is-the-token'
window.$nuxt.$apolloHelpers.onLogin(token)
window.$nuxt.$apolloHelpers.onLogout()
window.$nuxt.$apolloHelpers.onLogin(token)
expect(window.$nuxt.$apolloHelpers.getToken()).toContain(token)
})
// test('errorHandler', async () => {
// const window = await nuxt.renderAndGetWindow(url('/errorPage'))
// window.onNuxtReady(() => {
// expect(window.console.log).toContain('error: /errorPage')
// })
// })
})