Rantiev
Rantiev

Reputation: 2263

How to mock feathersjs mongodDB queries for unit testing?

I'm trying to find mocking solution for feathers unit tests, but only could find which require service rewrite (substitution in service initialisation), or mocking service with sinon (which makes no sense, as you can't check no hooks or other middleware logic)

I want to get everything as it was - only usage of any in memory db, or file system instead db. Without the need to rewrite services, or faking some services parts.

Something I'm tryint to achieve:

  if (process.env.NODE_ENV === 'test') {
    const fakeMongoServer = await MongoMemoryServer.create()

    app.configure(mongodbMock.bind(null, app, fakeMongoServer))
  } else {
    app.configure(mongodb)
  }

Upvotes: 0

Views: 37

Answers (0)

Related Questions