Add tests for async/await

This commit is contained in:
Sébastien Chopin 2016-12-27 16:31:25 +01:00
parent 8adb69468b
commit 45f22a418a
3 changed files with 40 additions and 0 deletions

View File

@ -56,6 +56,16 @@ test('/async-data', async t => {
t.true(html.includes('<p>Nuxt.js</p>'))
})
test('/await-async-data', async t => {
const { html } = await nuxt.renderRoute('/await-async-data')
t.true(html.includes('<p>Await Nuxt.js</p>'))
})
test('/callback-async-data', async t => {
const { html } = await nuxt.renderRoute('/callback-async-data')
t.true(html.includes('<p>Callback Nuxt.js</p>'))
})
test('/users/1', async t => {
const { html } = await nuxt.renderRoute('/users/1')
t.true(html.includes('<h1>User: 1</h1>'))

View File

@ -0,0 +1,17 @@
<template>
<p>{{ name }}</p>
</template>
<script>
const fetchData = () => {
return new Promise(resolve => {
setTimeout(() => resolve({ name: 'Await Nuxt.js' }), 10)
})
}
export default {
async data () {
return await fetchData()
}
}
</script>

View File

@ -0,0 +1,13 @@
<template>
<p>{{ name }}</p>
</template>
<script>
export default {
async data (context, callback) {
setTimeout(function () {
callback(null, { name: 'Callback Nuxt.js' })
}, 10)
}
}
</script>