-
Notifications
You must be signed in to change notification settings - Fork 27
Not mocking package under Jest #32
Comments
Seems like Jest has a |
Not a bother at all. For anyone else who sees this, I'm guessing the issue here is that Jest is probably using its own custom require method, which is how it handles things like auto-mocking. But as you discovered, you can just use Jest's mocking functionality and bypass mock-require altogether. |
@boblauer I really enjoy using your library. I use it in a bff (backend for frontend) that I have for a UI I am building and it works great. I usually run the bff in 'mocked' mode independently and that works perfectly, but I would like to run it in mocked mode for my jest tests. This causes problems, and I can't seem to find a way to get jest to mock modules that are deeper in my file hierarchy (like your library does beautifully). I tried mocking the 'mock-require' function with the Maybe you have some suggestions? Otherwise I'll just run the bff in a separate thread when I run my tests. |
Unfortunately I don't have any experience with using this library in parallel with Jest, so I'm afraid I don't have any suggestions on how to make it work. Sorry |
Thanks for the reply. :) I'll have to make do! |
Your mocking lib was beautifully intuitive and I was using it w/ mocha. Unfortunately I hate mocha so I was trying to move onto Jest. Unfortunately it didn't work there and Jest's mock lib for modules is not nearly as intuitive or elegant as yours. So, nice work on the lib 👍 |
Thank you for the kind words @NateZimmer . It's a bummer it doesn't work with Jest. |
Hi and thanks for this package, it seems really useful. Specially since there are some packages that cannot be mocked easily otherwise.
I am trying an example very similar to the one stated in the documentation:
When I try it with Node.js with
node plugins/index.test.js
(in my case) it works flawlessly printingpkg.sync() called
. However, with Jest (with slight modifications since at least one test is required) it does not seem to work:It prints the directory where the
package.json
is hosted, as thepkg-dir
library specifies (so it runs the original code). I have no idea how to even debug this since it seems like it's an issue with Jest + mock-require. I do not know the differences at runtime of Node.js and Jest, I thought Jest just loaded a couple of functions likeit()
andexpect()
but otherwise used a stock Node.js runtime.The text was updated successfully, but these errors were encountered: