feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

[Question] How to unit test when using @feathersjs/mongodb? #3438

Closed JPStrydom closed 3 months ago

JPStrydom commented 3 months ago

Question

When running a feathers app with MongoDB, how can one go about unit testing without having to connect to an actual MongoDB?

The documentation around test-database-setup (and this article) mentions that one can specify a local file path for nedb in the config/test.json file like so:

{
  "nedb": "../test/data"
}

The documentation and article also mentions that "The same thing can be done with connection strings for other databases.", but this does not seem to work for MongoDB.

I tried setting the following in the config/test.json file:

{
  "mongodb": "../test/data"
}

Which MongoDB doesn't seem to like.

Is there a recommended way by Feathers to mock out MongoDB? Looks like there are options like mongodb-memory-server and mongo-mock, but don't want to sink too much time into those if Feathers has a better way of achieving this.

Thanks!

System configuration

Module versions (especially the part that's not working):

NodeJS version: v20