You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there! NTARH has support for all API route types. Testing catch-all routes shouldn't be too different from any other route, you just have to provide the expected params object.
Using the Next.js docs as an example (given URL /api/post/a/b/c):
/* file: test/main.test.ts */import{testApiHandler}from'next-test-api-route-handler';// Import the handler under test from the pages/api directoryimport*aspagesHandlerfrom'../pages/api/[...slug]';it('does what I want',async()=>{expect.hasAssertions();awaittestApiHandler({
pagesHandler,params: {slug: ['a','b','c']},test: async({ fetch })=>{constres=awaitfetch({method: 'POST'});awaitexpect(res.text()).resolves.toBe('Post: a, b, c');}});});
Repository owner
locked and limited conversation to collaborators
Feb 12, 2024
I'm not seeing any documentation related to catch all api routes. Is there support for this? Thank you so much for this amazing library :)
The text was updated successfully, but these errors were encountered: