-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
stub a function in another file than the tested file #1910
Comments
Module loaders are not Sinon's domain. Look into link level intercepters. We have a guide |
If I understand correctly, now sinon only stub function from the same file, right? It just for the sake of understanding on how things works now :) Thanks any how for the link and response ! |
TBH I never dug into the difference in Node between module.exports and just exports, so I wouldn't know about that. But regarding your question: no, it doesn't matter which file something is declared. What matters is how it is exposed and if it is possible to override it. That's details that you need to control, not Sinon. For this and various ways to attack your specific issue, these issues might be worth looking into: |
thanks I'll dig in how is it exposed since it appears to be the problem ! Thanks again for your help |
@fatso83 Also I just found what my problem was. when I require it 'normally' the sinon stub works correctly. Is it a normal behaviour, meaning is it normal for sinon's stub to not be called when the function is affected by destructuring ? |
We are trying to keep the GitHub issues list tidy and focused on bugs and feature discussions. This ticket looks like a usage question; please post it to StackOverflow and tag it with If you feel that your topic is an issue with Sinon, please open a new ticket and follow the guidelines for reporting an issue. @Sufiane What you are experiencing has nothing to do with Sinon, but explaining why will further spam other maintainers. Post a question to SO. We monitor those tags, as well as do others. |
@fatso83 thanks I will do ! edit: SO question and answer |
Describe the bug
I try to stub a function called in the file I'm attempting to test, this function is defined in an other file, file that I correctly require in the file I want to test (see example below).
But it seems that the stub is never called, the real function is always used no matter what.
With sinon 1.17.6 (old version I know, older project) it worked properly, the stub was used instead of the real function. Right now I'm using sinon ^6.1.5
Is there anything I forgot to do? or Did I misunderstood something?
Thanks in advance for any help !
To Reproduce
For example:
foo.js (The file I wish to test)
bar.js
foo.test.js
Expected behavior
I expect the function to be stubbed and the stub to be called (or to throws in this case)
Screenshots
No disponible at the moment, I could try to provide some if needed
Context (please complete the following information):
sinon: ^6.1.5
test runner: jest
(my older project that worked, was using mocha as test runner)
The text was updated successfully, but these errors were encountered: