Testing in App Router. Using import server-only how can I write tests in jsdom
Unanswered
Short-tailed Shearwater posted this in #help-forum
Short-tailed ShearwaterOP
Trying to test a server page component in the App Router. However the test won’t run because one of my functions uses “server-only” but still require jsdom in my test environment. Has anyone resolved this issue?
2 Replies
Dutch
think them like backend api and use required test tools for backend
European Turtle-Dove
You can mock the (server-only) function in your test so it doesn't actually run in the jsdom environment. Alternatively isolate server-only logic from components so your tests only import client-safe code.