Open polizinha opened 3 years ago
rewiremock.enable();
/ rewiremock.disable();
are definetely not working as you might expected them, as 1) they have nothing to do 2) they react only to require
call between them, which is not happening.
Actually, from what I can see 'mongodb
has got replaced by mongoMock
. So what is not working in this case?
In the log, we can see connection (caller TestDbHelper.connect), after this, my test that calls getCollection
. In this point, we don't have this.client
and this.uri
anymore (populated in connection). So, he tried to connect again and use undefined this.uri
and we will have a failure.
I tested that flow without rewiremock (using conditionals with process.env.NODE_ENV
inside code) and It worked. So, I think I'm doing something wrong with rewiremock.
Sorry. The actual test is not visible to me and there is no way I can help here:
getCollection
?TestDbHelper
? How it's been used?this.url
is to call connect
, the logic in getCollection
just cannot work!
Hi! I'm mocking mongodb in my mocha tests with rewiremock and mongo-mock. I can rewire my wrapper that contains the mongo lib, but when another module calls that file, it doesn't have the started configuration like database, collections... I think it's something like cached modules, but I don't know what to do anymore. I have:
common.js
dbHelper.js
lib/mongo.js
When the feature that is being tested calls
getCollection
,this.client
isundefined
and all will fail.Can you help me?