-
I'm new to Next.js and I have previously tested my API endpoint using supertest. That worked fine until I tried to get the parsed URL parameters in an API - just keep getting Same happened then using next-test-api-route-handler until I specifically set the I'm just trying to understand what's actually going on. What's different from calling the API in a test from actually doing the request from the frontend? Is there some middleware in next that isn't run when running the test? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Your instincts are correct that Next.js is invoking some dynamic parameter parsing "middleware" somewhere else that is not invoked when just running the API resolver function in isolation, and certainly not when emulating Next.js routing via a request testing library (supertest, node-mocks-http, etc). In fact, Next.js's API resolver function uses dependency injection to get its URL parameters object, which NTARH takes full advantage of to inject the This answer might shed more light on things too. |
Beta Was this translation helpful? Give feedback.
Your instincts are correct that Next.js is invoking some dynamic parameter parsing "middleware" somewhere else that is not invoked when just running the API resolver function in isolation, and certainly not when emulating Next.js routing via a request testing library (supertest, node-mocks-http, etc). In fact, Next.js's API resolver function uses dependency injection to get its URL parameters object, which NTARH takes full advantage of to inject the
params
object during testing. This is why settingparams
in NTARH just works 🙂.This answer might shed more light on things too.