DaniJG / sinon-mongo

A Node library that simplifies writing unit tests using sinon for mocking code using the MongoDB client.
MIT License
4 stars 5 forks source link

Any chance to support mongodb driver versions >= 4.x.x #12

Closed viorelzavoiu closed 3 years ago

viorelzavoiu commented 3 years ago

Hi, I noticed that there is a new major mongodb driver 4.0.1. I got it when I hit npm install mongodb and I got the latest. But when I ran the tests I noticed a problem:

TypeError: The constructor should be a function.
    at stub.createStubInstance (D:\work\project\node_modules\sinon\lib\sinon\stub.js:128:15)
    at Sandbox.createStubInstance (D:\work\project\node_modules\sinon\lib\sinon\sandbox.js:74:52)
    at Object.sinon.mongo.collection (D:\work\project\node_modules\sinon-mongo\lib\sinon-mongo.js:43:49)

Here is the sample code:

const sinon = require('sinon');
require('sinon-mongo');
describe("Sample class test", function () {
    const mockCollection = sinon.mongo.collection({})
})

and my deps:

 "dependencies": {
    "mongodb": "^4.0.1",
  },
  "devDependencies": {
    "sinon": "^11.1.1",
    "sinon-mongo": "^1.1.0"
  }

I guess the problem is from the mongodb version not the sinon version, because I have another project in which I use sinon@11.1.1 and mongodb@3.6.6 and everything is fine. I noticed that in the peerDependencies is mentioned that "mongodb": ">= 3.1.13 < 4", so I was wondering if you plan to support mongodb@4.x.x. in the near future. Thanks a lot :D !!!

DaniJG commented 3 years ago

Certainly, just need to find some time to update it!