提交 f578089d 编写于 作者: A Arunoda Susiripala 提交者: GitHub

Fix page loader page normalization issue (#1844)

* Add integration tests for nested componentDidMount

* Fix the page loader normalization issue.

* Fix a typo in the url.
上级 2e7bc107
......@@ -19,7 +19,8 @@ export default class PageLoader {
throw new Error('Route name should start with a "/"')
}
return route.replace(/index$/, '')
if (route === '/') return route
return route.replace(/index$/, '').replace(/\/$/, '')
}
loadPage (route) {
......
import React, {Component} from 'react'
export default class extends Component {
constructor (props) {
super(props)
this.state = {
mounted: false
}
}
componentDidMount () {
this.setState({mounted: true})
}
render () {
return <p>ComponentDidMount {this.state.mounted ? 'executed on client' : 'not executed'}.</p>
}
}
import CDM from '../../lib/cdm'
export default CDM
import CDM from '../lib/cdm'
export default CDM
......@@ -321,5 +321,31 @@ export default (context, render) => {
browser.close()
})
})
describe('with different types of urls', () => {
it('on normal page', async () => {
const browser = await webdriver(context.appPort, '/with-cdm')
const text = await browser.elementByCss('p').text()
expect(text).toBe('ComponentDidMount executed on client.')
browser.close()
})
it('on dir/index page ', async () => {
const browser = await webdriver(context.appPort, '/nested-cdm/index')
const text = await browser.elementByCss('p').text()
expect(text).toBe('ComponentDidMount executed on client.')
browser.close()
})
it('on dir/ page ', async () => {
const browser = await webdriver(context.appPort, '/nested-cdm/')
const text = await browser.elementByCss('p').text()
expect(text).toBe('ComponentDidMount executed on client.')
browser.close()
})
})
})
}
......@@ -42,6 +42,7 @@ describe('Basic Features', () => {
renderViaHTTP(context.appPort, '/stateful'),
renderViaHTTP(context.appPort, '/stateless'),
renderViaHTTP(context.appPort, '/styled-jsx'),
renderViaHTTP(context.appPort, '/with-cdm'),
renderViaHTTP(context.appPort, '/nav'),
renderViaHTTP(context.appPort, '/nav/about'),
......@@ -49,7 +50,9 @@ describe('Basic Features', () => {
renderViaHTTP(context.appPort, '/nav/self-reload'),
renderViaHTTP(context.appPort, '/nav/hash-changes'),
renderViaHTTP(context.appPort, '/nav/shallow-routing'),
renderViaHTTP(context.appPort, '/nav/redirect')
renderViaHTTP(context.appPort, '/nav/redirect'),
renderViaHTTP(context.appPort, '/nested-cdm/index')
])
})
afterAll(() => stopApp(context.server))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册