Skip to content

NextJS with Jest and Nuqs #938

Open
Open
@f1yingbanana

Description

@f1yingbanana

Context

What's your version of nuqs?

    "nuqs": "^2.4.1",

What framework are you using?

  • ✅ Next.js (app router)

Which version of your framework are you using?

    "next": "15.0.3",

Description

I am unable to test with nuqs without mocking in NextJS and Jest. NextJS has its own code transformer and Jest config wrapper, so it is difficult to follow the Nuqs/Jest guide and use experimental ESM support. Instead, I've been relying on NextJS config transpilePackages option to port the node packages back to CommonJS.

However, with the esm-only.cjs file, I'll get an exception in my tests. But even if I remove the manual exception, my test still cannot find the correct module. I suspect maybe #880 might fix this, but with the NextJS Jest wrapper over Jest config, it didn't work :(

Really want to not mock and wish jest supports ESM out of the box :( but meanwhile, are there any workarounds?

Reproduction

  1. Setup Jest in NextJS following NextJS testing guide
  2. Try to use Nuqs in a Jest test
  3. Fails :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    adapters/testingUses the testing adapter for mocking URL behaviours in tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions