Commit 9a4226c1 authored by Arunoda Susiripala's avatar Arunoda Susiripala Committed by Tim Neutkens

Add test case for reloading the page on page script error (#3798)

* Add a test for reloading the page on page script error.

* Add a comment.
parent 6de3ff9d
import Link from 'next/link'
import { Component } from 'react'
import Router from 'next/router'
let counter = 0
export default class extends Component {
increase () {
counter++
this.forceUpdate()
}
visitQueryStringPage () {
const href = { pathname: '/nav/querystring', query: { id: 10 } }
const as = { pathname: '/nav/querystring/10', hash: '10' }
Router.push(href, as)
}
render () {
return (
<div id='counter-page'>
<Link href='/no-such-page'><a id='no-such-page'>No Such Page</a></Link>
<p>This is the home.</p>
<div id='counter'>
Counter: {counter}
</div>
<button id='increase' onClick={() => this.increase()}>Increase</button>
</div>
)
}
}
......@@ -93,6 +93,28 @@ describe('Production Usage', () => {
const data = await renderViaHTTP(appPort, '/static/data/item.txt')
expect(data).toBe('item')
})
it('should reload the page on page script error', async () => {
const browser = await webdriver(appPort, '/counter')
const counter = await browser
.elementByCss('#increase').click().click()
.elementByCss('#counter').text()
expect(counter).toBe('Counter: 2')
// When we go to the 404 page, it'll do a hard reload.
// So, it's possible for the front proxy to load a page from another zone.
// Since the page is reloaded, when we go back to the counter page again,
// previous counter value should be gone.
const counterAfter404Page = await browser
.elementByCss('#no-such-page').click()
.waitForElementByCss('h1')
.back()
.waitForElementByCss('#counter-page')
.elementByCss('#counter').text()
expect(counterAfter404Page).toBe('Counter: 0')
browser.close()
})
})
describe('X-Powered-By header', () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment