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

Add test for instance method on getInitialProps. (#5951)

This commit is contained in:
Anderson Leite 2018-12-26 14:30:16 -08:00 committed by Tim Neutkens
parent 44d12d0c95
commit 2c916137b2
2 changed files with 24 additions and 0 deletions

View file

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

View file

@ -120,6 +120,12 @@ export default function ({ app }, suiteName, render, fetch) {
expect(link.text()).toBe('About')
})
test('getInitialProps should be class method', async () => {
const $ = await get$('/instance-get-initial-props')
const expectedErrorMessage = '"InstanceInitialPropsPage.getInitialProps()" is defined as an instance method - visit https://err.sh/zeit/next.js/get-initial-props-as-an-instance-method for more information.'
expect($('pre').text().includes(expectedErrorMessage)).toBeTruthy()
})
test('getInitialProps resolves to null', async () => {
const $ = await get$('/empty-get-initial-props')
const expectedErrorMessage = '"EmptyInitialPropsPage.getInitialProps()" should resolve to an object. But found "null" instead.'