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:
parent
44d12d0c95
commit
2c916137b2
18
test/integration/basic/pages/instance-get-initial-props.js
Normal file
18
test/integration/basic/pages/instance-get-initial-props.js
Normal 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
|
||||
}
|
|
@ -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.'
|
||||
|
|
Loading…
Reference in a new issue