mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
Add tests for async/await
This commit is contained in:
parent
8adb69468b
commit
45f22a418a
@ -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>'))
|
||||
|
17
test/fixtures/basic/pages/await-async-data.vue
vendored
Normal file
17
test/fixtures/basic/pages/await-async-data.vue
vendored
Normal 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>
|
13
test/fixtures/basic/pages/callback-async-data.vue
vendored
Normal file
13
test/fixtures/basic/pages/callback-async-data.vue
vendored
Normal 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>
|
Loading…
Reference in New Issue
Block a user