From 78fa6b191d24525f9d8285c0c8b775c759af5a57 Mon Sep 17 00:00:00 2001 From: Dan Zajdband Date: Sun, 16 Oct 2016 00:32:58 -0400 Subject: [PATCH] Added async props test (#9) --- test/fixtures/basic/pages/async-props.js | 18 ++++++++++++++++++ test/index.js | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/basic/pages/async-props.js diff --git a/test/fixtures/basic/pages/async-props.js b/test/fixtures/basic/pages/async-props.js new file mode 100644 index 00000000..2401e133 --- /dev/null +++ b/test/fixtures/basic/pages/async-props.js @@ -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

{this.props.name}

+ } +} diff --git a/test/index.js b/test/index.js index d90a7844..596d9db6 100644 --- a/test/index.js +++ b/test/index.js @@ -19,7 +19,7 @@ test(async t => { }) test(async t => { - const html = await (render('/stateful')) + const html = await render('/stateful') t.true(html.includes('

The answer is 42

')) }) @@ -29,6 +29,11 @@ test(async t => { t.true(html.includes('

I can haz meta tags

')) }) +test(async t => { + const html = await render('/async-props') + t.true(html.includes('

Diego Milito

')) +}) + function render (url, ctx) { return _render(url, ctx, { dir, staticMarkup: true }) }