I am trying to learn unit testing in past few days. I have following test file ::var expect = require('chai').expect;var _ = require("lodash");var gridV2 = require('../routes/v1/mobile/gridV2');let req = {ids : [1,2,3]}, res = {};describe('TEST', function () {it('Test 1', function (done) {gridV2.fetchData(req,res, function (){//this function modifies req object do some checks on req and call donedone();});})});The fetchData function is like this :fetchData : function (req, res, next) {db.fetchDatafromDB(req.ids, function (results){next();})}How do I mock fetchDatafromDB call as it's making a db call. I know we can use sinon but I am not finding any helpful tutorials.
Submitted November 29, 2019 at 07:10AM by GhostFoxGod
No comments:
Post a Comment