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

Remove UNSAFE_ lifecycles from tests (#5031)

* Remove UNSAFE_componentWillMount

* Remove UNSAFE_componentWillReceiveProps from lifecycle
This commit is contained in:
Tim Neutkens 2018-08-25 20:09:20 +02:00 committed by GitHub
parent 9532cc1256
commit dfafad488a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 37 deletions

View file

@ -11,13 +11,15 @@ export default class UrlPropChange extends React.Component {
}
// eslint-disable-next-line camelcase
UNSAFE_componentWillReceiveProps (nextProps) {
this.setState(() => {
return {
previousUrl: this.props.url,
url: nextProps.url
}
})
componentDidUpdate (prevProps) {
if (prevProps.url !== this.props.url) {
this.setState(() => {
return {
previousUrl: prevProps.url,
url: this.props.url
}
})
}
}
render () {

View file

@ -1,23 +0,0 @@
import React, { Component } from 'react'
export default class Statefull extends Component {
constructor (props) {
super(props)
this.state = { answer: null }
}
// eslint-disable-next-line camelcase
UNSAFE_componentWillMount () {
this.setState({ answer: 42 })
}
render () {
return (
<div>
<p id='answer'>The answer is {this.state.answer}</p>
</div>
)
}
}

View file

@ -35,7 +35,6 @@ describe('Basic Features', () => {
renderViaHTTP(context.appPort, '/head'),
renderViaHTTP(context.appPort, '/json'),
renderViaHTTP(context.appPort, '/link'),
renderViaHTTP(context.appPort, '/stateful'),
renderViaHTTP(context.appPort, '/stateless'),
renderViaHTTP(context.appPort, '/fragment-syntax'),
renderViaHTTP(context.appPort, '/custom-extension'),

View file

@ -20,12 +20,6 @@ export default function ({ app }, suiteName, render, fetch) {
expect(html.includes('My component!')).toBeTruthy()
})
test('renders a stateful component', async () => {
const $ = await get$('/stateful')
const answer = $('#answer')
expect(answer.text()).toBe('The answer is 42')
})
// default-head contains an empty <Head />.
test('header renders default charset', async () => {
const html = await (render('/default-head'))