How do we setup Jest for unit testing? #7234
Replies: 4 comments 5 replies
-
On your Jest config, maybe adding a way for Jest to resolve the Webpack alias modules can help fix this. We do use this in our own repo config. For example, you can try: {
moduleNameMapper: {
'@docusaurus/(BrowserOnly|ComponentCreator|constants|ExecutionEnvironment|Head|Interpolate|isInternalUrl|Link|Noop|renderRoutes|router|Translate|use.*)': '@docusaurus/core/src/client/exports/$1',
'@theme/(.*)': '@docusaurus/theme-classic/src/theme/$1',
'@site/(.*)': 'website/$1',
}
} Note: the |
Beta Was this translation helpful? Give feedback.
-
I, too, have spent the majority of the day trying to create a test case for a custom component that uses Docusarus dependencies. I tried the suggestions in this thread, but to no avail. Something interesting I noticed is that no one is testing their custom components. I took a glance at the showcase page, and none of the repositories I visited had test cases for custom components. Are we, as a community, not testing our custom components? Is it because of the challenges we are facing? |
Beta Was this translation helpful? Give feedback.
-
@slorber First of all thank you so much for the detailed blog. We implemented a very similar solution, except we went with Playwright to do the comparison versus using Argos. Instead of storing the images in git, we use GitHub Artifacts. The report is posted on a GitHub page - we create a unique URL per test run. Thank you for sharing this with us. This definitely goes a long way in helping us feel more confident about rolling out changes 💪🏻 |
Beta Was this translation helpful? Give feedback.
-
@lanegoolsby @slorber any update about this discussion. I met the same issue that I use jest to mock
|
Beta Was this translation helpful? Give feedback.
-
I've been trying to setup Jest. I am unable to get it working though.
The problem I cannot get past is getting Jest to recognize the Docusaurus modules. I've attached a minimum reproduction of the issue. I know its a configuration issue but I've come at this problem dozens of different directions all to no avail.
unit-tests.zip
Beta Was this translation helpful? Give feedback.
All reactions