Unverified Commit 6ba53d8f authored by JJ Kasper's avatar JJ Kasper Committed by GitHub
parent 5cf7408b
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Error Overlay for server components createContext called in Server Component should show error when React.createContext is called 1`] = `
" 1 of 1 unhandled error
Server Error
TypeError: createContext only works in Client Components. Add the \\"use client\\" directive at the top of the file to use it. Read more: https://beta.nextjs.org/docs/rendering/server-and-client-components#context
This error happened while generating the page. Any console logs will be displayed in the terminal window.
app/page.js (3:24) @ React
1 |
2 | import React from 'react'
> 3 | const Context = React.createContext()
| ^
4 | export default function Page() {
5 | return (
6 | <>"
`;
exports[`Error Overlay for server components createContext called in Server Component should show error when React.createContext is called in external package 1`] = `
" 1 of 1 unhandled error
Server Error
TypeError: createContext only works in Client Components. Add the \\"use client\\" directive at the top of the file to use it. Read more: https://beta.nextjs.org/docs/rendering/server-and-client-components#context
This error happened while generating the page. Any console logs will be displayed in the terminal window.
null"
`;
exports[`Error Overlay for server components createContext called in Server Component should show error when createContext is called in external package 1`] = `
" 1 of 1 unhandled error
Server Error
TypeError: createContext only works in Client Components. Add the \\"use client\\" directive at the top of the file to use it. Read more: https://beta.nextjs.org/docs/rendering/server-and-client-components#context
This error happened while generating the page. Any console logs will be displayed in the terminal window.
null"
`;
......@@ -3,6 +3,7 @@ import { sandbox } from './helpers'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import path from 'path'
import { check } from 'next-test-utils'
describe('Error Overlay for server components', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
......@@ -51,7 +52,12 @@ describe('Error Overlay for server components', () => {
await browser.refresh()
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource(true)).toMatchSnapshot()
await check(async () => {
expect(await session.getRedboxSource(true)).toContain(
`TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component`
)
return 'success'
}, 'success')
expect(next.cliOutput).toContain(
'createContext only works in Client Components'
)
......@@ -100,7 +106,14 @@ describe('Error Overlay for server components', () => {
await browser.refresh()
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource(true)).toMatchSnapshot()
await check(async () => {
expect(await session.getRedboxSource(true)).toContain(
`TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component`
)
return 'success'
}, 'success')
expect(next.cliOutput).toContain(
'createContext only works in Client Components'
)
......@@ -149,11 +162,17 @@ describe('Error Overlay for server components', () => {
await browser.refresh()
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource(true)).toMatchSnapshot()
await check(async () => {
expect(await session.getRedboxSource(true)).toContain(
`TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component`
)
return 'success'
}, 'success')
expect(next.cliOutput).toContain(
'createContext only works in Client Components'
)
await cleanup()
})
})
......
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