Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure to handle failing to load _error (#10617)
- Loading branch information
Showing
4 changed files
with
111 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const Page = () => 'oops' | ||
|
||
Page.getInitialProps = () => { | ||
throw new Error('oops') | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Link from 'next/link' | ||
|
||
export default () => ( | ||
<> | ||
<Link href="/broken"> | ||
<a id="to-broken">to oops</a> | ||
</Link> | ||
</> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* eslint-env jest */ | ||
/* global jasmine */ | ||
import path from 'path' | ||
import webdriver from 'next-webdriver' | ||
import { | ||
nextBuild, | ||
nextStart, | ||
findPort, | ||
killApp, | ||
waitFor, | ||
} from 'next-test-utils' | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1 | ||
const appDir = path.join(__dirname, '..') | ||
|
||
describe('Failing to load _error', () => { | ||
it('handles failing to load _error correctly', async () => { | ||
await nextBuild(appDir) | ||
const appPort = await findPort() | ||
const app = await nextStart(appDir, appPort) | ||
|
||
const browser = await webdriver(appPort, '/') | ||
await browser.eval(`window.beforeNavigate = true`) | ||
|
||
await browser.elementByCss('#to-broken').moveTo() | ||
await browser.waitForElementByCss('script[src*="broken.js"') | ||
|
||
// stop app so that _error can't be loaded | ||
await killApp(app) | ||
|
||
await browser.elementByCss('#to-broken').click() | ||
await waitFor(2000) | ||
|
||
expect(await browser.eval('window.beforeNavigate')).toBeFalsy() | ||
}) | ||
}) |