next.js/test/development/app-dir/serialize-circular-error/serialize-circular-error.test.ts
serialize-circular-error.test.ts51 lines1.4 KB
import { nextTestSetup } from 'e2e-utils'

describe('serialize-circular-error', () => {
  const { next } = nextTestSetup({
    files: __dirname,
  })

  it('should serialize the object from server component in console correctly', async () => {
    const browser = await next.browser('/')

    await expect(browser).toDisplayRedbox(`
     {
       "code": "E394",
       "description": "An error occurred but serializing the error message failed.",
       "environmentLabel": "Server",
       "label": "Runtime Error",
       "source": null,
       "stack": [],
     }
    `)
    const output = next.cliOutput
    expect(output).toContain(
      'Error: {"objA":{"other":{"a":"[Circular]"}},"objB":"[Circular]"}'
    )
  })

  it('should serialize the object from client component in console correctly', async () => {
    const browser = await next.browser('/client')

    // TODO: Format arbitrary messages in Redbox
    await expect(browser).toDisplayRedbox(`
     {
       "code": "E394",
       "description": "[object Object]",
       "environmentLabel": null,
       "label": "Runtime Error",
       "source": null,
       "stack": [],
     }
    `)

    const bodyText = await browser.elementByCss('body').text()
    expect(bodyText).toContain('This page couldn\u2019t load')

    const output = next.cliOutput
    expect(output).toContain(
      'Error: {"objC":{"other":{"a":"[Circular]"}},"objD":"[Circular]"}'
    )
  })
})
Quest for Codev2.0.0
/
SIGN IN