-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock called, but not stubbing dependency #139
Comments
I've re-written my use of rewiremock, and am able to get it to mock properly:
Notice that loadFromFS isn't directly required by I do have another question - Is it possible to |
Hey, sorry for quite a late answer, but it's better late that never? History note - rewiremock supports different "models" of work in order to help migration from other libraries existing before it. In short If you want to mocks something else in the same test you need to do At the same time you can change rules a little bit and mock rewiremock('@data/utils/queries-loader').with({loadFromFS: mockLoadFromFS});
const serverFile = require('../server/src/server'); In this you can do the following trick const loaderMock = rewiremock('@data/utils/queries-loader')
.callThrough() // pass to real file
.dynamic() // allow changes in the future
const serverFile = require('../server/src/server');
// update mocking in the future
loaderMock.with({loadFromFS: mockLoadFromFS}); Keep in mind |
I am trying to test an express API.
Upon calling one of the endpoints, the API calls the function
loadFromFS
. I'd like to mock its return value.The files are as follows:
Log:
As you can see, initially the variable customersQuery, is loaded as usual by , and then mocked. Even after it is mocked,
foo
gets the un-mocked version of it.If I move customersQuery to the inner scope of
foo
, the mock function is never called.Any help would be appreciated.
Thank you.
Node version v14.15.4
rewiremock 3.14.3.
mocha 9.1.3
The text was updated successfully, but these errors were encountered: