Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hannes Bornö committed Oct 3, 2022
1 parent 1ad18fe commit 3822e72
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 3 deletions.
Expand Up @@ -2,8 +2,11 @@ import path from 'path'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver'
import { check, renderViaHTTP } from 'next-test-utils'

describe('app-dir root layout', () => {
const isDev = (global as any).isNextDev

describe('app-dir mpa navigation', () => {
if ((global as any).isNextDeploy) {
it('should skip next deploy for now', () => {})
return
Expand All @@ -18,9 +21,9 @@ describe('app-dir mpa navigation', () => {
beforeAll(async () => {
next = await createNext({
files: {
app: new FileRef(path.join(__dirname, 'mpa-navigation/app')),
app: new FileRef(path.join(__dirname, 'root-layout/app')),
'next.config.js': new FileRef(
path.join(__dirname, 'mpa-navigation/next.config.js')
path.join(__dirname, 'root-layout/next.config.js')
),
},
dependencies: {
Expand All @@ -31,6 +34,30 @@ describe('app-dir mpa navigation', () => {
})
afterAll(() => next.destroy())

if (isDev) {
describe('Missing required tags', () => {
it('should error on page load', async () => {
const outputIndex = next.cliOutput.length
renderViaHTTP(next.url, '/missing-tags').catch(() => {})
await check(
() => next.cliOutput.slice(outputIndex),
/Missing required root layout tags: html, head, body/
)
})

it('should error on page navigation', async () => {
const outputIndex = next.cliOutput.length
const browser = await webdriver(next.url, '/has-tags')
await browser.elementByCss('a').click()

await check(
() => next.cliOutput.slice(outputIndex),
/Missing required root layout tags: html, head, body/
)
})
})
}

describe('Should do a mpa navigation when switching root layout', () => {
it('should work with basic routes', async () => {
const browser = await webdriver(next.url, '/basic-route')
Expand Down
@@ -0,0 +1,10 @@
export default function Root({ children }) {
return (
<html>
<head>
<title>Hello World</title>
</head>
<body>{children}</body>
</html>
)
}
@@ -0,0 +1,5 @@
import Link from 'next/link'

export default function Page() {
return <Link href="/missing-tags">To incorrect root layout</Link>
}
@@ -0,0 +1,3 @@
export default function Root({ children }) {
return children
}
@@ -0,0 +1,3 @@
export default function Page() {
return <p>WORLD!</p>
}
File renamed without changes.

0 comments on commit 3822e72

Please sign in to comment.