Replies: 3 comments 5 replies
-
Hi, I've had the same question and I've checked Blitz.js approach: they use This is the warning I get using Mongoose + jsdom environment:
|
Beta Was this translation helpful? Give feedback.
-
I noticed that Blitz use Jest projects to have server-side (node) and client-side (jsdom) Jest tests: https://github.com/blitz-js/blitz/blob/canary/packages/blitz/jest-preset.js#L50-L82 |
Beta Was this translation helpful? Give feedback.
-
After a bit of difficulty I managed to utilize Jest projects to create separate configurations for server-side (node) and client-side (jest-environment-jsdom) tests. Here's how I do it in my project.
|
Beta Was this translation helpful? Give feedback.
-
I have a custom link component that extends the material ui link component and has some extra behavior to handle external links by looking at the current window.location.protocol and setting target if it's offsite. I have two Jest unit tests for this component to check both that it renders using material ui's createMount wrapper around enzyme and that the offsite linking logic works. My logic for getting the current url is:
const checkHref = window.location.protocol + '//' + window.location.host;
This works great once the app has loaded client side, and it passes my jest test. But if I attempt to SSR this component I get an error "window is not defined". Great, so I'll switch to node for the testEnvironment - now my createMount test fails. How can I write a test for this component that will correctly fail on SSR, but pass on client side rendering?
Beta Was this translation helpful? Give feedback.
All reactions