Closed nodkz closed 8 years ago
When I was having a simliar problem, the issue was the Mongoose Connection. Try to save a reference to your connection and use it specifically to create all Models and operations.
@danielstern many thanks for the temporary hack!
But I hope that this problem will be resolved in proper way.
I suspect this is fixed in Jest 15 because of the new defaults. See facebook.github.io/jest/blog/2016/09/01/jest-15.html
Let me know if this still persists and we can reopen and troubleshoot.
@danielstern do u have an example of how to save a mongoose connection?
I am having issues with this. I was having a hard time trying to see what was causing it but I am pretty sure it is Jest as it is working fine in production and on Mocha.
Currently having the same issue, using jest ^20.0.4 & mongoose ^4.11.5
@Negan1911 I for some reason was able to solve it when I tried to replicate the issue for the purposes of giving a example repo. I am not sure what happened. But maybe that is worth a try. Jest caches quite aggressively because of doing things on workers and it could be a worker is stuck. They suggest uninstalling and re-installing as well but that did not work either. I just found moving to another repo and trying to do something apparently frees up the cache. Might be worth a try.
Tried with the example repo of above and failed, i don't think that is because of jest cache because i ran the tests inside a Docker container, and equally fails, i'd make sure that it started clean and i got the same result
Could you told me what version of jest&mongoose are using? maybe it is a regression issue
For me Jest is working perfectly. You may see these examples:
After digging some hours with this issue, i found that the problem indeed is having this property resetModules: true
on the jest.config.js
which make sense because you'll need to mantain the module since it has the connection. So even if seems the same problem it isn't. thanks!
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. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
Yesterday I whole day try to test mongoose models with jest. Firstly, think that problem with me and my hands. And I tried tons of variants jest's configs, re-read tons of issues. And at last I take
mocha
and it started up with the first kick.It seems, that
Object.create
some-how not fixed properly (https://github.com/facebook/jest/issues/933)Mongoose internally use
Object.create
for creating instances.Repo with test: https://github.com/nodkz/jest_mocha_mongoose Broken jest test:
npm run test
Same success mocha test:npm run test-mocha
npm debug file npm@3.8.9, node@v6.2.0 jest-cli@12.1.1
jest output file: