Abstracting class using mongoose Abstracting class using mongoose mongoose mongoose

Abstracting class using mongoose


I'm not familiar with the import syntax (nor EMCASCRIPT-6), though you say you're using node.js, so I'd recommend using the proxquire package. The idea is that the package allows you to require an external package, while stubbing the requirements that that package would use. So in your case, you could do something like:

proxyquire('../my/class/that/uses/mongoose', {    mongoose: MyTestMongooseImplementation})

Which would allow you to use your own mongoose implementation while still using your MongooseUser as you have defined it in your package. Alternatively, you could just override the the MongooseUser class (path relative to the the file whose requirements you are stubbing:

proxyquire('/path/to/UserMongooseRepository', {    '../../auth/mongooseModel/MongooseUser': MyTestMongooseUser})

Documentation: https://www.npmjs.com/package/proxyquire