Issues with Clerk and Unit testing

I am working on a project for work and we have a strict requirement for unit tests. I decided to go with Vitest and we're using Clerk for auth. I ran into two different issues and I'm not sure which path is easier to solve. When I run the test (one so far) using the render method from @testing-library/react I get an error that "AuthContext not found". That made sense so I used a pattern I've used elsewhere of making a wrapper for render that wraps all children in a ClerkProvider. When I do that I get a new error that says ClerkProvider.js 2 seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package "@clerk/nextjs" asking them to ship the file in .mjs extension or add "type": "module" in their package.json. I'm unsure how to proceed as the only issue I currently have with Clerk is that they have zero guidance on how to set up any tests within the auth context. Hoping someone has encountered this and has a pointer towards a solve.
Solution:
SOLVED: After talking with Clerk it seems that two things were necessary. I needed to use the require syntax to import the Clerk provider in my wrapper, and I needed to pull in the AppRouterContext as well.
Jump to solution
1 Reply
Solution
JudgeJLo
JudgeJLo8mo ago
SOLVED: After talking with Clerk it seems that two things were necessary. I needed to use the require syntax to import the Clerk provider in my wrapper, and I needed to pull in the AppRouterContext as well.
Want results from more Discord servers?
Add your server