Skip to content

[NEXT-863] Unable to test page components using metadata API with Jest #47299

@andremendonca

Description

@andremendonca

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000
    Binaries:
      Node: 18.12.1
      npm: 8.19.2
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.2.5-canary.8
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Jest (next/jest)

Link to the code that reproduces this issue

https://github.com/andremendonca/metadata-jest-error

To Reproduce

git clone https://github.com/andremendonca/metadata-jest-error.git
npm i
npm test

Describe the Bug

in NextJs 13+ using the experimental App folder, I cannot test any server component that exports metadata or generateMetadata from https://beta.nextjs.org/docs/api-reference/metadata

Resulting in the following error:

 × NEXT_RSC_ERR_CLIENT_METADATA_EXPORT: metadata
       ╭─[/metadata-jest-bug/app/page.tsx:1:1]
     1 │ export const metadata = {
       ·              ────────
     2 │   title: 'My jest sample'
     3 │ }
       ╰────

Expected Behavior

I expected to be able to test Server Components present on app directory

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

From SyncLinear.com | NEXT-863

Metadata

Metadata

Assignees

No one assigned

    Labels

    MetadataRelated to Next.js' Metadata API.TestingRelated to testing with Next.js.locked

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions