Unverified Commit c1e5b66c authored by Darsh Patel's avatar Darsh Patel Committed by GitHub

Fix: space issue in error overlay and add tests (#15617)

parent 3d98171d
......@@ -62,7 +62,7 @@ function makeClickable(text: string): JSX.Element[] | string {
return (
<>
<a href={word}>{word}</a>
{index === array.length - 1 ? ' ' : ''}
{index === array.length - 1 ? '' : ' '}
</>
)
}
......
export default function Index() {
throw new Error('This error should be clickable. https://nextjs.org')
throw new Error(
'This error should be clickable. https://nextjs.org is the homepage. Visit https://nextjs.org/docs for documentation'
)
}
/* eslint-env jest */
import { findPort, killApp, launchApp, hasRedbox } from 'next-test-utils'
import {
findPort,
killApp,
launchApp,
hasRedbox,
getRedboxHeader,
evaluate,
waitFor,
} from 'next-test-utils'
import webdriver from 'next-webdriver'
import { join } from 'path'
......@@ -23,14 +31,67 @@ describe('Clickable error link', () => {
await hasRedbox(browser)
await browser.eval(`(function () {
document.querySelector("nextjs-portal")
.shadowRoot
.querySelector("#nextjs__container_errors_desc > a").click()
})()
`)
await evaluate(browser, () => {
document
.querySelector('body > nextjs-portal')
.shadowRoot.querySelector(
'#nextjs__container_errors_desc > a:nth-child(1)'
)
.click()
})
await waitFor(1000)
const url = await browser.url()
expect(url).toBe('https://nextjs.org/')
})
it('Handles multiple links in error', async () => {
const browser = await webdriver(appPort, '/first')
// Open the first link from error
await hasRedbox(browser)
await evaluate(browser, () => {
document
.querySelector('body > nextjs-portal')
.shadowRoot.querySelector(
'#nextjs__container_errors_desc > a:nth-child(1)'
)
.click()
})
await waitFor(1000)
const url1 = await browser.url()
// Go back to error page
await browser.back()
// Open the second link from error
await hasRedbox(browser)
await evaluate(browser, () => {
document
.querySelector('body > nextjs-portal')
.shadowRoot.querySelector(
'#nextjs__container_errors_desc > a:nth-child(2)'
)
.click()
})
await waitFor(1000)
const url2 = await browser.url()
expect({ url1, url2 }).toEqual({
url1: 'https://nextjs.org/',
url2: 'https://nextjs.org/docs',
})
})
it('Shows error message correctly', async () => {
const browser = await webdriver(appPort, '/first')
await hasRedbox(browser)
const headerText = await getRedboxHeader(browser)
expect(headerText).toMatch(
/Error: This error should be clickable\. https:\/\/nextjs\.org is the homepage\. Visit https:\/\/nextjs\.org\/docs for documentation/
)
})
})
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