Mock/Stub a function (a npm module) with callback using Sinon

422 Views Asked by At

I'm using json2csv npm module to convert the json response to csv format, the code looks like below..

json2csv({ data: data, fields: ['id', 'firstName', 'lastName'] }, function (err, csv) {
          if (err) {
            reject(err);
          } else {
            resolve(csv);
          }
        });

How to stub the above function using sinon so i can write unit tests for success and error scenarios. My unit testing stack is Jasmine and Istanbul.

0

There are 0 best solutions below