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

Add a test for reloading the page on page script error with prefetch (#3811)

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

* Click the correct link.
This commit is contained in:
Arunoda Susiripala 2018-02-15 15:52:11 +05:30 committed by Tim Neutkens
parent 24d862cd6b
commit 30b0be1aaf
2 changed files with 31 additions and 1 deletions

View file

@ -20,6 +20,8 @@ export default class extends Component {
return (
<div id='counter-page'>
<Link href='/no-such-page'><a id='no-such-page'>No Such Page</a></Link>
<br />
<Link href='/no-such-page' prefetch><a id='no-such-page-prefetch'>No Such Page (with prefetch)</a></Link>
<p>This is the home.</p>
<div id='counter'>
Counter: {counter}

View file

@ -7,7 +7,8 @@ import {
nextBuild,
startApp,
stopApp,
renderViaHTTP
renderViaHTTP,
waitFor
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import fetch from 'node-fetch'
@ -115,6 +116,33 @@ describe('Production Usage', () => {
browser.close()
})
it('should reload the page on page script error with prefetch', async () => {
const browser = await webdriver(appPort, '/counter')
const counter = await browser
.elementByCss('#increase').click().click()
.elementByCss('#counter').text()
expect(counter).toBe('Counter: 2')
// Let the browser to prefetch the page and error it on the console.
await waitFor(3000)
const browserLogs = await browser.log('browser')
expect(browserLogs[0].message).toMatch(/Page does not exist: \/no-such-page/)
// 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-prefetch').click()
.waitForElementByCss('h1')
.back()
.waitForElementByCss('#counter-page')
.elementByCss('#counter').text()
expect(counterAfter404Page).toBe('Counter: 0')
browser.close()
})
})
describe('X-Powered-By header', () => {