Comments (7)
Seems like Jest has a .mock()
method so I will be using that. Sorry for bothering you :)
from mock-require.
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.
from mock-require.
@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 jest.mock
(or jest.doMock
or jest.setMock
) but it doesn't seem to work when it is an external file.
Maybe you have some suggestions? Otherwise I'll just run the bff in a separate thread when I run my tests.
from mock-require.
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
from mock-require.
Thanks for the reply. :) I'll have to make do!
from mock-require.
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 đ
from mock-require.
Thank you for the kind words @NateZimmer . It's a bummer it doesn't work with Jest.
from mock-require.
Related Issues (20)
- Using mock require to replace FS module and create a drop in replacement for in-memory filesystems HOT 3
- Use normalize() for consistency in Windows HOT 1
- Issue with mock path HOT 1
- Weird stuff (unmocking might be broken) with Node.js 8 HOT 12
- `caller.getTypeName is not a function` HOT 5
- Module._load alignment with Node HOT 2
- travis ci HOT 3
- Impossible to return strings HOT 4
- Unexpected Behaviour HOT 1
- Mocking Nested Dependencies HOT 1
- The mocked module is still loaded HOT 2
- mocking nested dependencies HOT 8
- How is this difference from Sinon-like packages? HOT 1
- reRequiring index files returns startMocking HOT 1
- Cannot get to work with an express route module HOT 4
- Introduce a changelog and version tags
- `stop` and `stopAll` should also clear out the cache of previously mocked module HOT 1
- mocking nested dependencies
- Still maintained ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ī¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mock-require.