williamkapke / mongo-mock

Let's pretend we have a real MongoDB
MIT License
240 stars 74 forks source link

Add entry point that mocks global MongoDB #150

Open LinusU opened 3 years ago

LinusU commented 3 years ago

Currently we are using something like this to test our API with a mocked version of MongoDB, without having to specifically having to code the app to know anything about Mongo Mock:

const mock = require('mongo-mock')
const real = require('mongodb')

mock.max_delay = 0
real.MongoClient = mock.MongoClient
real.ObjectId = mock.ObjectId

I think that it could be a benefit to add this as an entry point to this package, the same way that e.g. dotenv/config works. Providing this instead of letting every end users write their own has some benefits: