Next.js Discord

Discord Forum

TypeError: (0 , _slug.handler) is not a function ...

Unanswered
Honey bee posted this in #help-forum
Open in Discord
Avatar
Honey beeOP
Next.js 12.3.4 with jest 29.7.0 using /src/pages/api/some/endpoint/[slug].js

The endpoint works fine when I call it when running. But as a test i get the full error:

(0 , _slug.handler) is not a function TypeError: (0 , _slug.handler) is not a function at Object.<anonymous> (/Users/username/git/org/my-framework-api/src/tests/api/cdol/leaders/[slug].test.js:69:30) at Promise.then.completed (/Users/username/git/org/my-framework-api/node_modules/jest-circus/build/utils.js:298:28) ...

=======
// /src/pages/api/cdol/leaders/[slug].js
import { withApiAuthRequired } from "@auth0/nextjs-auth0";
const handler = withApiAuthRequired(async function handle(req, res) {
...
});
export default handler;

=======
// /src/tests/api/cdol/leaders/[slug].test.js
import { handler ] from "../../../../pages/api/cdol/leaders/[slug]
it("simple happy path", async () => {
... //setup mocks include req
const result = await handler(req)
});

0 Replies