Closed bartvanderwal closed 8 years ago
I'm not sure, but https://github.com/elliotf/mocha-mongoose/blob/4039af6a980ca5983c3a103d1689503db4a1c3ad/example/test.js#L6 might be the problem. It works in the repo because require('../index')
will resolve to https://github.com/elliotf/mocha-mongoose/blob/4039af6a980ca5983c3a103d1689503db4a1c3ad/index.js which is the mocha-mongoose library.
If you copy it to a different place, require('../index')
will likely yield something other than mocha-mongoose. If you change require('../index')
to require('mocha-mongoose')
(after installing mocha-mongoose) then the test should work correctly.
Thanks for the quick reply @elliotf! :+1:
I got my hopes up, but checked my code and it doesn't use index
, so they went down somewhat.
As I mentioned I had copied the code from the README.md
instead of the actual test.js
file. There alread mocha-mongoose
is used instead of index
in the require.
However I then decided to copy over the test.js and do your fix. And now it works! Evidently there is some difference between the file. I'm now gonna play Sherlock and do some diffing to see what it is, cause I can't spot it with naked eye.
Well, I don't know. There is no difference, README.md is fine!
I did see that I had renamed the Dummy
model in the test code to Seller
. I just renamed it again after I had it working in the original situation. Now it's still working after, so I think I missed something with that small refactoring causing it to behave like that.
Anyway thanks for the quick help!
You're very welcome! Please feel free to close this ticket if/when you like.
Great repo!
However, can you tell me what I'm doing wrong here? I added the tests from
/example/test.js
file from theREADME.md
into a new/test/test.js
file to some test project. But when I then run the test I get an error:It fails in the first test, or even before it, in the
before
when opening connection. Increasing timeout makes no difference.When I clone this exact repo instead and run the test, it works fine (using the same mongodb url; (
mongodb://localhost/<somedb>
):What am I doing wrong? I'd like to add mongoose unit tests to a production app, but am pretty sure I'll get the same error there.
Note: I also checked that all required packages of mocha-mongoose were in the other project with same version: