-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Fails to mock certain libraries #90
Comments
FWIW, I ran into a similar issue like this as well with ampersand-state except an "undefined is not a function" error. Had to add it to the dont mock section in package.json |
Ran into similar issues with the mongoose & winston modules compounded by issue #110 which stomps on the console output when the process dies so that the errors weren't clear. https://www.npmjs.org/package/mongoose I understand that configuring these modules not to be mocked would get me around the exceptions, however, these are libraries that I need to mock in order to test the smallest unit of relevant code in my code base. I was hoping that jest would keep me from having to do the work of manually mocking these types of dependencies, but resorted to doing just that. |
I have simular problems loading joi: This happens with jest.dontMock('joi') and without it.
|
I've the same problem loading the Looking at the code for
I also tried I'm guessing the only workaround is a manual mock in here somewhere? |
@tcoopman I was able to get
Presumably you wouldn't need the |
Regarding my previous comment about mocking
Is there a cleaner way to do that? I've tried quite a few things with
when I have Has anyone been successful testing code that uses cc: @tcoopman |
FWIW, I did get
|
+1 |
Getting error:
And if I dontMock everything under bluebird, I get segmentation fault $ jest
Using Jest CLI v0.4.0
Waiting on 1 test...Segmentation fault: 11
$ and I do this jest
.dontMock('bluebird')
.dontMock('../node_modules/bluebird/js/main/any.js')
.dontMock('../node_modules/bluebird/js/main/assert.js')
.dontMock('../node_modules/bluebird/js/main/async.js')
.dontMock('../node_modules/bluebird/js/main/bind.js')
.dontMock('../node_modules/bluebird/js/main/bluebird.js')
// ...
.dontMock('../node_modules/bluebird/js/main/using.js')
.dontMock('../node_modules/bluebird/js/main/util.js') |
I also have problem working with bluebird. Same error message. (related facebook/react-native#516 (comment)) |
FYI here is what I did to work around the problem. In my project root I have a file in 'use strict';
jest.autoMockOff();
module.exports = require.requireActual('bluebird');
jest.autoMockOn(); |
@amasad Thanks, this workaround is working for me. |
@amasad workaround also worked for me 👍 |
Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed. |
@amasad thank you for the workaround. |
Any update on this? I'm running into this problem when using a symlink in |
Could we get a response from you, please? |
Certainly! Unfortunately it is hard to auto-mock something at runtime that uses meta-programming for its implementation without ES2015 Proxies which aren't properly implemented in any engine yet. For these cases there are always two solutions:
In a lot of cases you don't actually want mocking. You probably always want an unmocked version of bluebird; there is no point in mocking a Promise library. |
The proper solution to this problem is to put "bluebird" into the "unmockedModulePathPatterns" config. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
We ran into an issue on a project where Jest borked when requiring a certain library (in this case Bluebird http://github.com/petkaantonov/bluebird).
I set up an isolated example to see if the result was the same...
I wonder if it's something to do with how Bluebird is written? I'm really not sure. We resorted to overhauling our test setup because of this.
The code: https://github.com/callum/jest-issue
Seems like it could be the same issue as #59
The text was updated successfully, but these errors were encountered: