Home » Unit Test

Start writing Unit Test of mongoose model using Test Jest

Get Started Install Jest using yarn: yarn add –dev jest npm: npm install –save-dev jest More detail about jest https://jestjs.io/docs/en/getting-started   we need mongodb-memory-server-core package.  This package spins up a actual/real MongoDB Server programmatically from node for testing or mocking…

Read More »

Using Sinon to stub Mongoose calls and return Promise

Suppose we have a schema var User = require(‘./schemas/UserSchema’).User; and we want to write unit test for like bellow code: var getUserById = function () { return User.findOne({_id: ‘001’}).exec(); }; Before writing unit test we can mock the…

Read More »