-
Hi, I have a dynamic route that gets an id from the params object like in the nextjs docs: export async function GET(
req: NextRequest,
{ params }: { params: { recipeId: string } }
) {
const { recipeId } = params;
/*
Do some fun stuff with the recipeId
*/
return NextResponse.json({});
} I test this route with a test like this: import { testApiHandler } from 'next-test-api-route-handler';
import * as appHandler from './route';
describe('GET /api/recipes/[recipeId]', () => {
test('should return recipes', async () => {
await testApiHandler({
appHandler,
params: { recipeId: '1' },
async test({ fetch }) {
/*
assertions
*/
},
});
});
}); There is a type error when passing appHandler as a param:
The appHandler is expected to have params as of type Record<string, string, string[]>. I didn't find a way in the docs where I can change the type neatly in the test. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Interesting, I'll take a look. |
Beta Was this translation helpful? Give feedback.
-
Alright, this seems like a Next.js and TypeScript thing rather than an NTARH thing. The mismatch here is likely caused by You're correct that this should be supported per the Next.js docs. |
Beta Was this translation helpful? Give feedback.
-
This should be resolved with v4.0.4 |
Beta Was this translation helpful? Give feedback.
This should be resolved with v4.0.4