TypeError: (0 , _slug.handler) is not a function - nextjs 12/jest

  1. 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) });

Hi @harris.johnny,

Welcome to the Auth0 Community!

Is the line (0 , _slug.handler) somewhere in your code? I’m not familiar with this in the context of Auth0.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.