1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Added async props test (#9)

This commit is contained in:
Dan Zajdband 2016-10-16 00:32:58 -04:00 committed by Guillermo Rauch
parent e527098bb9
commit 78fa6b191d
2 changed files with 24 additions and 1 deletions

View file

@ -0,0 +1,18 @@
import React from 'react'
export default class AsyncProps extends React.Component {
static async getInitialProps () {
return await AsyncProps.fetchData()
}
static fetchData () {
const p = new Promise(resolve => {
setTimeout(() => resolve({ name: 'Diego Milito' }), 10)
})
return p
}
render () {
return <p>{this.props.name}</p>
}
}

View file

@ -19,7 +19,7 @@ test(async t => {
})
test(async t => {
const html = await (render('/stateful'))
const html = await render('/stateful')
t.true(html.includes('<div><p>The answer is 42</p></div>'))
})
@ -29,6 +29,11 @@ test(async t => {
t.true(html.includes('<div><h1>I can haz meta tags</h1></div>'))
})
test(async t => {
const html = await render('/async-props')
t.true(html.includes('<p>Diego Milito</p>'))
})
function render (url, ctx) {
return _render(url, ctx, { dir, staticMarkup: true })
}