-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathindex.test.js
More file actions
51 lines (46 loc) · 1.58 KB
/
Copy pathindex.test.js
File metadata and controls
51 lines (46 loc) · 1.58 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
import test from 'ava'
import moxios from 'moxios'
import createNuxt from './helpers/create-nuxt'
// We keep the nuxt and server instance
// So we can close them at the end of the test
let nuxt = null
const req = {
headers: {
'accept-language': 'zh'
},
session: {
jwt: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.' +
'eyJhdWQiOlsidGF0Il0sInVzZXJfbmFtZSI6IlRlc3RlciIsI' +
'nNjb3BlIjpbInJlYWQiXSwiZXhwIjoxNDk0MjY4ODY0LCJ1c2' +
'VySWQiOiIxIiwiYXV0aG9yaXRpZXMiOlsiYWRtaW4iXSwianR' +
'pIjoiN2FkN2VjYzUtNTdmNy00MmZlLThmZmQtYjUxMTJkNTZm' +
'M2NhIiwiY2xpZW50X2lkIjoidGF0LWNsaWVudCJ9.' +
'ovWxqcBptquNR5QUBz1it2Z3Fr0OxMvWsnXHIHTcliI'
}
}
// TODO: refactor test
// Init nuxt.js and create server listening on localhost:4000
test.before('Init Nuxt.js', async (t) => {
// mock axios
moxios.install()
moxios.stubRequest('/hpi/auth/captcha', {
status: 200,
data: '验证码Mock'
})
nuxt = createNuxt()
await nuxt.listen(3000, 'localhost')
})
// Example of testing only generated html
test.skip('Route /', async (t) => {
const { html } = await nuxt.renderRoute('/', Object.assign({}, { req }))
t.true(html.includes('Application boilerplate based on Vue.js 2.x, Koa 2.x, Element-UI, Axios, Vue i18n and Nuxt.js'))
})
test.skip('Route /about', async (t) => {
const { html } = await nuxt.renderRoute('/about', Object.assign({}, { req }))
t.true(html.includes('<h1>About Page</h1>'))
})
// Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', async (t) => {
moxios.uninstall()
await nuxt.close()
})