next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Unable to test route.ts handlers with Jest

Open JarrodMFlesch opened this issue 1 year ago • 0 comments

Link to the code that reproduces this issue

https://github.com/JarrodMFlesch/next-jest-route-handlers

To Reproduce

  1. Clone the repository down
  2. yarn && yarn test

Current vs. Expected behavior

Should be able to test route handlers from a test file.

In the repository, I am spinning up a custom server that should allow me to process requests throughout the lifecycle of the test runner. I cannot figure out why this is not working, might be a limitation? If so, calling this out in the docs would be appreciated.

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020
Binaries:
  Node: 18.18.2
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.14.0
Relevant Packages:
  next: 14.1.1-canary.27 // Latest available version is detected (14.1.1-canary.27).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.3.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Jest (next/jest), Middleware / Edge (API routes, runtime)

Which stage(s) are affected? (Select all that apply)

next dev (local)

Additional context

No response

JarrodMFlesch avatar Feb 01 '24 17:02 JarrodMFlesch