I have the following classes A and B,
class A {
listenResponse(port, callback) {
const server = new CustomServer(port, (error, response) => {
if (error) return callback(error);
callback(null, response);
});
}
}
class CustomServer {
constructor(port, callback) {
this.port = port;
this.server = http.createServer((request, response) => {
if(// condition) { return callback(error); }
callback(null, response);
});
}
}
How do I test the function passed to CustomServer constructor while unit testing class A? Any help is highly appreciated.
Here is the unit test solution using an additional module proxyquire:
a.js:
const CustomServer = require('./customServer');
class A {
listenResponse(port, callback) {
const server = new CustomServer(port, (error, response) => {
if (error) return callback(error);
callback(null, response);
});
}
}
module.exports = A;
customServer.js:
class CustomServer {
constructor(port, callback) {
this.port = port;
this.server = http.createServer((request, response) => {
callback(null, response);
});
}
}
module.exports = CustomServer;
a.test.js:
const sinon = require('sinon');
const proxyquire = require('proxyquire');
describe('60084056', () => {
it('should get response', () => {
const error = null;
const response = {};
const customServerStub = sinon.stub().yields(error, response);
const A = proxyquire('./a.js', {
'./customServer': customServerStub,
});
const a = new A();
const port = 3000;
const callback = sinon.stub();
a.listenResponse(port, callback);
sinon.assert.calledWithExactly(customServerStub, port, sinon.match.func);
sinon.assert.calledWithExactly(callback, null, response);
});
it('should handle error', () => {
const error = new Error('network');
const response = {};
const customServerStub = sinon.stub().yields(error, response);
const A = proxyquire('./a.js', {
'./customServer': customServerStub,
});
const a = new A();
const port = 3000;
const callback = sinon.stub();
a.listenResponse(port, callback);
sinon.assert.calledWithExactly(customServerStub, port, sinon.match.func);
sinon.assert.calledWithExactly(callback, error);
});
});
Unit test results with coverage report:
60084056
✓ should get response (1684ms)
✓ should handle error
2 passing (2s)
-----------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------
All files | 70 | 100 | 50 | 66.67 |
a.js | 100 | 100 | 100 | 100 |
customServer.js | 25 | 100 | 0 | 25 | 3-5
-----------------|---------|----------|---------|---------|-------------------
Source code: https://github.com/mrdulin/expressjs-research/tree/master/src/stackoverflow/60084056
Related
I have written a test code to test code that gives credentials from AWS Secret Manager. I used proxyquire and sinon for stubbing and getting this error.
Function I want to test
exports.getCredsFromAWSSecretsManager = (keyName) => {
const SM = new AWS.SecretsManager({
apiVersion: process.env.AWS_SM_API_VERSION,
region: process.env.AWS_SM_REGION
});
return SM.getSecretValue(params).promise().then((data) => {
logger.info(logMsgs.awsHlpr_smGetSecretValueSuccess(JSON.stringify(data)));
return JSON.parse(data.SecretString);
}).catch((err) => {
logger.error(logMsgs.awsHlpr_smGetSecretValueErr(JSON.stringify(err)));
throw err;
});
};
Test case that I have written
const sinon = require("sinon");
const proxyquire = require("proxyquire").noCallThru().noPreserveCache();
const { mockLogger } = require("../../mockdata/mockLogger");
let awsHelper;
let secretsManagerStub;
describe.only("AWS Helper ", () => {
// function1
describe("AWS Helper: getCredsFromAWSSecretsManagera method", () => {
before((done) => {
const data = {
SecretString: JSON.stringify({ publicKey: 'secretUsername', privateKey: 'secretPassword' }),
};
secretsManagerStub = {
getSecretValue: sinon.stub().callsFake((params, callback) => {
callback(null, data);
}),
};
const awsStub = {
SecretsManager: sinon.stub().returns(secretsManagerStub)
}
awsHelper = proxyquire('../../../utils/aws_helper.js', {
'aws-sdk':{
AWS:awsStub
} ,
"../../utils/logger": mockLogger,
});
done();
});
afterEach(() => {
sinon.restore();
});
it('should write random data!', async () => {
const expectedData = "abcdef";
secretsManagerStub.getSecretValue.yields(null, expectedData);
const data = await awsHelper.getCredsFromAWSSecretsManager();
sinon.assert.callCount(secretsManagerStub.getSecretValue, 1);
assert.strictEqual(data, expectedData);
});
});
});
This code gives me the error saying
TypeError: AWS.SecretsManager is not a constructor
any help would be greatly appreciated.
AWS is a namespace, it contains all AWS service classes like SecretsManager. You should provide the awsStub to aws-sdk, there is no need to wrap the awsStub inside an object.
aws_helper.js:
const AWS = require('aws-sdk');
exports.getCredsFromAWSSecretsManager = () => {
const SM = new AWS.SecretsManager({
apiVersion: process.env.AWS_SM_API_VERSION,
region: process.env.AWS_SM_REGION,
});
const params = {
SecretId: '1',
};
return SM.getSecretValue(params)
.promise()
.then((data) => {
console.info(data);
return JSON.parse(data.SecretString);
})
.catch((err) => {
console.error(err);
throw err;
});
};
aws_helper.test.js:
const sinon = require('sinon');
const proxyquire = require('proxyquire').noCallThru().noPreserveCache();
let awsHelper;
let secretsManagerStub;
describe('AWS Helper: getCredsFromAWSSecretsManagera method', () => {
before(() => {
const data = {
SecretString: JSON.stringify({ publicKey: 'secretUsername', privateKey: 'secretPassword' }),
};
secretsManagerStub = {
getSecretValue: sinon.stub().returnsThis(),
promise: sinon.stub().resolves(data),
};
const awsStub = {
SecretsManager: sinon.stub().returns(secretsManagerStub),
};
awsHelper = proxyquire('./aws_helper.js', {
'aws-sdk': awsStub,
});
});
afterEach(() => {
sinon.restore();
});
it('should write random data!', async () => {
const data = await awsHelper.getCredsFromAWSSecretsManager();
sinon.assert.callCount(secretsManagerStub.getSecretValue, 1);
sinon.assert.match(data, { publicKey: 'secretUsername', privateKey: 'secretPassword' });
});
});
test result:
AWS Helper: getCredsFromAWSSecretsManagera method
{
SecretString: '{"publicKey":"secretUsername","privateKey":"secretPassword"}'
}
✓ should write random data!
1 passing (2s)
---------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|-------------------
All files | 77.78 | 100 | 66.67 | 77.78 |
aws_helper.js | 77.78 | 100 | 66.67 | 77.78 | 19-20
---------------|---------|----------|---------|---------|-------------------
The following line in my unit test:
sandbox.stub(myAPI,'getPeople').returns([500, {errorCode: '500'}])
is giving me the following error:
TypeError: Cannot stub non-existent property getPeople
I'm trying to stub an error response from my API call to test my error handling.
The unit test:
const chai = require('chai');
const sinonChai = require('sinon-chai');
const sinon = require('sinon');
const { getPeopleHandler } = require('../services/handlers/get-people-handler');
const { expect } = chai;
const myAPI = require('../services/api');
chai.use(sinonChai);
describe('handle error', () => {
let req;
let res;
let sandbox;
describe('getPeopleHandler() with error', () => {
before(() => {
req = {
session: {}
};
res = {
render: () => ({})
};
sandbox = sinon.createSandbox();
});
beforeEach(() => {
sandbox.stub(myAPI,'getPeople').returns([500, {errorCode: '500'}]);
})
afterEach(() => {
sandbox.restore();
});
it('should render the error page', async () => {
sandbox.stub(res, 'render').returns({});
res.locals = {};
await getPeopleHandler(req, res);
expect(res.render).to.have.been.calledOnceWith('error.html');
});
});
});
api.js
const fetch = require('node-fetch');
const getPeople = (url) => {
console.log(`About to call API at ${url}`);
return new Promise((resolve, reject) => {
fetch(url, { method: 'GET' })
.then(res => Promise.all([res.status, res.json()]))
.then(([status, jsonData]) => {
resolve([status, jsonData]);
}).catch(error => {
console.log('e', error)
reject(error)
})
})
};
module.exports = getPeople;
get-people-handler.js
const callAPI = require('../../services/api');
const config = require('../../config/config');
const getPeopleHandler = async (req, res) => {
const url = config.getPeopledataUrl;
const response = await callAPI(url);
console.log(`API call status = ${response[0]}`);
if (response[0] === 200) {
res.locals.list = response[1];
res.render('people.html');
} else {
res.locals.error = response[0];
res.render('error.html');
}
};
module.exports = { getPeopleHandler };
You are stub the getPeople function because you use module.exports. If you want to export a object, you should do it like this:
module.exports = { getPeople };
sinon.stub(object, "method")
Replaces object.method with a stub function. An exception is thrown if the property is not already a function.
Below is a working example:
api.js:
const fetch = require('node-fetch');
const getPeople = (url) => {
console.log(`About to call API at ${url}`);
return new Promise((resolve, reject) => {
fetch(url, { method: 'GET' })
.then((res) => Promise.all([res.status, res.json()]))
.then(([status, jsonData]) => {
resolve([status, jsonData]);
})
.catch((error) => {
console.log('e', error);
reject(error);
});
});
};
module.exports = { getPeople };
config.js:
module.exports = {
getPeopledataUrl: 'http://localhost:3000/api/people',
};
get-people-handler.js:
const api = require('./api');
const config = require('./config');
const getPeopleHandler = async (req, res) => {
const url = config.getPeopledataUrl;
const response = await api.getPeople(url);
console.log(`API call status = ${response[0]}`);
if (response[0] === 200) {
res.locals.list = response[1];
res.render('people.html');
} else {
res.locals.error = response[0];
res.render('error.html');
}
};
module.exports = { getPeopleHandler };
get-people-handler.test.js:
const sinon = require('sinon');
const { getPeopleHandler } = require('./get-people-handler');
const myAPI = require('./api');
describe('handle error', () => {
let req;
let res;
let sandbox;
describe('getPeopleHandler() with error', () => {
before(() => {
req = {
session: {},
};
res = {
render: () => ({}),
};
sandbox = sinon.createSandbox();
});
beforeEach(() => {
sandbox.stub(myAPI, 'getPeople').returns([500, { errorCode: '500' }]);
});
afterEach(() => {
sandbox.restore();
});
it('should render the error page', async () => {
sandbox.stub(res, 'render').returns({});
res.locals = {};
await getPeopleHandler(req, res);
sinon.assert.calledWithExactly(res.render, 'error.html');
});
});
});
test result:
handle error
getPeopleHandler() with error
API call status = 500
✓ should render the error page
1 passing (7ms)
-----------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------------|---------|----------|---------|---------|-------------------
All files | 60.87 | 50 | 16.67 | 60.87 |
api.js | 30 | 100 | 0 | 30 | 4-13
config.js | 100 | 100 | 100 | 100 |
get-people-handler.js | 83.33 | 50 | 100 | 83.33 | 9-10
-----------------------|---------|----------|---------|---------|-------------------
I am trying to write a unit test case using mocha framework, where I have to mock an azure redis cache...Can someone help me on how to mock cache for unit test case purpose using node.js.
const redis = require('redis');
const redisHostName = process.env['hostName'];
const redisPort = process.env['port'];
const redisKey = process.env['key'];
let client = redis.createClient(redisPort, redisHostName, { auth_pass: redisKey, tls: { serverName: redisHostName } });
async function getKeyValue(key, ctx) {
context = ctx;
return new Promise((resolve, reject) => {
client.get(key, function (err, result) {
if (err) {
resolve(err);
}
resolve(result);
});
});
}
getKeyValue();
Here is the unit test solution:
index.js
const redis = require('redis');
const redisHostName = process.env['hostName'];
const redisPort = process.env['port'];
const redisKey = process.env['key'];
let client = redis.createClient(redisPort, redisHostName, { auth_pass: redisKey, tls: { serverName: redisHostName } });
async function getKeyValue(key, ctx) {
context = ctx;
return new Promise((resolve, reject) => {
client.get(key, function(err, result) {
if (err) {
return resolve(err);
}
resolve(result);
});
});
}
exports.getKeyValue = getKeyValue;
index.test.js:
const sinon = require('sinon');
const redis = require('redis');
describe('60870408', () => {
beforeEach(() => {
process.env['hostName'] = '127.0.0.1';
process.env['port'] = 6379;
process.env['key'] = 'test';
});
afterEach(() => {
delete require.cache[require.resolve('./')];
sinon.restore();
});
it('should get value', async () => {
const client = {
get: sinon.stub().callsFake((key, callback) => callback(null, 'elsa')),
};
const createClientStub = sinon.stub(redis, 'createClient').returns(client);
const { getKeyValue } = require('./');
sinon.assert.calledWithExactly(createClientStub, '6379', '127.0.0.1', {
auth_pass: 'test',
tls: { serverName: '127.0.0.1' },
});
const actual = await getKeyValue('name', {});
sinon.assert.match(actual, 'elsa');
sinon.assert.calledWithExactly(client.get, 'name', sinon.match.func);
});
it('should handle error', async () => {
const mError = new Error('network');
const client = {
get: sinon.stub().callsFake((key, callback) => callback(mError)),
};
const createClientStub = sinon.stub(redis, 'createClient').returns(client);
const { getKeyValue } = require('./');
sinon.assert.calledWithExactly(createClientStub, '6379', '127.0.0.1', {
auth_pass: 'test',
tls: { serverName: '127.0.0.1' },
});
const actual = await getKeyValue('name', {});
sinon.assert.match(actual, mError);
sinon.assert.calledWithExactly(client.get, 'name', sinon.match.func);
});
});
unit test results with 100% coverage:
60870408
✓ should get value
✓ should handle error
2 passing (28ms)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
index.js | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
For some reason I am having a little trouble getting this simple test to run correctly with a similar set-up I have used multiple times before.
Perhaps a fresh pair of eyes could help me understand why my method generateReport is not being invoked and none of my stubs are being triggered with the intended arguments?
BYE nor GOOD are ever logged and the tests are returning the error: AssertError: expected stub to be called with arguments
My index file:
const errorHandler = require('./lib/handlers/error-handler')
const transformRequest = require('./lib/handlers/request-converter')
const convert = require('./lib/convert')
exports.generateReport = function generateReport(req, res) {
console.log('HELLO')
const objectToPopulateTemplate = transformRequest(req.body)
convert(objectToPopulateTemplate, function (e, data) {
if (e) {
console.log('BYE')
const error = errorHandler(e)
return res.send(error.httpCode).json(error)
}
console.log('GOOD')
res
.set('Content-Type', 'application/pdf')
.set('Content-Disposition', `attachment; filename=velocity_report_${new Date()}.pdf`)
.set('Content-Length', data.length)
.status(200)
.end(data)
})
}
My test file:
const proxyquire = require('proxyquire')
const assert = require('assert')
const sinon = require('sinon')
const fakeData = require('./data/sample-request.json')
describe('report-exporter', () => {
describe('generateReport', () => {
const fakeError = new Error('Undefined is not a function')
let res, resSendStub, resStatusStub, resEndStub, resSetStub, resJsonStub, req, convertStub, generate
before(() => {
resSendStub = sinon.stub()
resJsonStub = sinon.stub()
resStatusStub = sinon.stub()
resEndStub = sinon.stub()
resSetStub = sinon.stub()
convertStub = sinon.stub()
res = {
send: function(errorCode) {
return resSendStub(errorCode)
},
json: function(object) {
return resJsonStub(object)
},
set: function(arg1, arg2) {
return resSetStub(arg1, arg2)
},
status: function(code) {
return resStatusStub(code)
},
end: function(data) {
return resEndStub(data)
}
}
req = {
body: {}
}
generate = proxyquire('./../index', {
'./lib/convert': function() {
return convertStub
}
})
})
it('Should return an error response', () => {
convertStub.throws(fakeError)
generate.generateReport(req, res)
sinon.assert.calledWith(resSendStub, '500')
})
})
})
It looks like you are proxyquireing your ./lib/convert incorrectly. Original convert is called with objectToPopulateTemplate and a callback function (e, data). And that's the callback who is responsible for error handling and sending a response.
The stubbed convert function though doesn't care about about the provided callback at all, so the callback never gets called.
Most likely what you want is to pass the parameters to convertStub and deal with them later:
'./lib/convert': function(objectToPopulateTemplate, cb) {
return convertStub(objectToPopulateTemplate, cb);
}
and then
it('Should return an error response', () => {
generate.generateReport(req, res);
const cb = convertStub.getCall(0).args[1];
// simulate `convert` to fail
cb(fakeError);
sinon.assert.calledWith(resSendStub, '500')
})
Here is the unit test solution:
index.js:
const errorHandler = require("./error-handler");
const transformRequest = require("./request-converter");
const convert = require("./convert");
exports.generateReport = function generateReport(req, res) {
console.log("HELLO");
const objectToPopulateTemplate = transformRequest(req.body);
convert(objectToPopulateTemplate, function(e, data) {
if (e) {
console.log("BYE");
const error = errorHandler(e);
return res.send(error.httpCode).json(error);
}
console.log("GOOD");
res
.set("Content-Type", "application/pdf")
.set(
"Content-Disposition",
`attachment; filename=velocity_report_${new Date()}.pdf`
)
.set("Content-Length", data.length)
.status(200)
.end(data);
});
};
error-handler.js:
module.exports = function(error) {
return error;
};
request-converter.js:
module.exports = function transformRequest(body) {
return body;
};
convert.js:
module.exports = function convert(body, callback) {
callback();
};
index.spec.js:
const sinon = require("sinon");
const proxyquire = require("proxyquire");
describe("report-exporter", () => {
describe("generateReport", () => {
afterEach(() => {
sinon.restore();
});
const fakeError = new Error("Undefined is not a function");
fakeError.httpCode = 500;
it("Should return an error response", () => {
const logSpy = sinon.spy(console, "log");
const mReq = { body: {} };
const mRes = { send: sinon.stub().returnsThis(), json: sinon.stub() };
const convertStub = sinon.stub();
const errorHandlerStub = sinon.stub().returns(fakeError);
const transformRequestStub = sinon.stub().returns(mReq.body);
const generate = proxyquire("./", {
"./convert": convertStub,
"./error-handler": errorHandlerStub,
"./request-converter": transformRequestStub
});
generate.generateReport(mReq, mRes);
convertStub.yield(fakeError, null);
sinon.assert.calledWith(transformRequestStub);
sinon.assert.calledWith(convertStub, {}, sinon.match.func);
sinon.assert.calledWith(errorHandlerStub, fakeError);
sinon.assert.calledWith(logSpy.firstCall, "HELLO");
sinon.assert.calledWith(logSpy.secondCall, "BYE");
});
});
});
Unit test result with coverage report:
report-exporter
generateReport
HELLO
BYE
✓ Should return an error response (94ms)
1 passing (98ms)
----------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------------------|----------|----------|----------|----------|-------------------|
All files | 87.5 | 50 | 62.5 | 87.5 | |
convert.js | 50 | 100 | 0 | 50 | 2 |
error-handler.js | 50 | 100 | 0 | 50 | 2 |
index.js | 84.62 | 50 | 100 | 84.62 | 14,15 |
index.spec.js | 100 | 100 | 100 | 100 | |
request-converter.js | 50 | 100 | 0 | 50 | 2 |
----------------------|----------|----------|----------|----------|-------------------|
Source code: https://github.com/mrdulin/mocha-chai-sinon-codelab/tree/master/src/stackoverflow/47352972
I'm trying to test a function which calls request.get() function inside it. What I'm trying is to cover all branches of the callback function. I'm trying to achieve it without separating the callback function to a different function because it's uses variables of the upper closure.
Here's an example to illustrate..
foo.js:
var request = require('request');
function func(arg1, arg2) {
request.get({...}, function(error, response, body) {
// do stuff with arg1 and arg2 // want to be covered
if (...) { // want to be covered
... // want to be covered
} else if (...) { // want to be covered
... // want to be covered
} else {
... // want to be covered
}
});
}
exports.func = func;
I tried to stub it with sinon as well as proxyquire.
foo.spec.js (stubbed with sinon):
var foo = require('./foo'),
var sinon = require('sinon'),
var request = require('request');
var requestStub = sinon.stub(request, 'get', function(options, callback) {
callback(new Error('Custom error'), {statusCode: 400}, 'body');
}); // Trying to replace it with a function that calls the callback immediately so not to deal with async operations in test
foo.func(5, 3);
foo.spec.js (stubbed with proxyquire):
var requestStub = {};
var proxyquire = require('proxyquire'),
var foo = proxyquire('./foo', {'request': requestStub}),
var sinon = require('sinon');
requestStub.get = function(options, callback) {
callback(new Error('Custom error'), {statusCode: 400}, 'body');
}; // Trying to replace it with a function that calls the callback immediately so not to deal with async operations in test
foo.func(5, 3);
Neither did work. When I tried to debug I never hit the callback function, which is suggesting that I didn't stub the request.get() method correctly making it still async operation.
I would appreciate someone tell me what I did wrong in both scenarios (sinon & proxyquire) and examples on how to fix it.
Here is an unit test solution using sinon and mocha:
index.js:
var request = require("request");
function func(arg1, arg2) {
request.get("https://github.com/mrdulin", function(error, response, body) {
console.log(arg1, arg2);
if (error) {
console.log(error);
} else if (response.status === 200) {
console.log(response);
} else {
console.log("others");
}
});
}
exports.func = func;
index.spec.js:
var foo = require("./");
var sinon = require("sinon");
var request = require("request");
describe("func", () => {
afterEach(() => {
sinon.restore();
});
it("should handle error", () => {
const logSpy = sinon.spy(console, "log");
const getStub = sinon.stub(request, "get");
foo.func(1, 2);
const mError = new Error("network error");
getStub.yield(mError, null, null);
sinon.assert.calledWith(
getStub,
"https://github.com/mrdulin",
sinon.match.func
);
sinon.assert.calledWith(logSpy.firstCall, 1, 2);
sinon.assert.calledWith(logSpy.secondCall, mError);
});
it("should handle response", () => {
const logSpy = sinon.spy(console, "log");
const getStub = sinon.stub(request, "get");
foo.func(1, 2);
const mResponse = { status: 200 };
getStub.yield(null, mResponse, null);
sinon.assert.calledWith(
getStub,
"https://github.com/mrdulin",
sinon.match.func
);
sinon.assert.calledWith(logSpy.firstCall, 1, 2);
sinon.assert.calledWith(logSpy.secondCall, mResponse);
});
it("should handle other situation", () => {
const logSpy = sinon.spy(console, "log");
const getStub = sinon.stub(request, "get");
foo.func(1, 2);
const mResponse = { status: 500 };
getStub.yield(null, mResponse, null);
sinon.assert.calledWith(
getStub,
"https://github.com/mrdulin",
sinon.match.func
);
sinon.assert.calledWith(logSpy.firstCall, 1, 2);
sinon.assert.calledWith(logSpy.secondCall, "others");
});
});
Unit test result with 100% coverage:
func
1 2
Error: network error
at Context.it (/Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/src/stackoverflow/37764363/index.spec.js:1:4103)
at callFn (/Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/node_modules/mocha/lib/runnable.js:387:21)
at Test.Runnable.run (/Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/node_modules/mocha/lib/runnable.js:379:7)
at Runner.runTest (/Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/node_modules/mocha/lib/runner.js:535:10)
at /Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/node_modules/mocha/lib/runner.js:653:12
at next (/Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/node_modules/mocha/lib/runner.js:447:14)
at /Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/node_modules/mocha/lib/runner.js:457:7
at next (/Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/node_modules/mocha/lib/runner.js:362:14)
at Immediate._onImmediate (/Users/ldu020/workspace/github.com/mrdulin/mocha-chai-sinon-codelab/node_modules/mocha/lib/runner.js:425:5)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
✓ should handle error (48ms)
1 2
{ status: 200 }
✓ should handle response
1 2
others
✓ should handle other situation
3 passing (58ms)
---------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
---------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
index.js | 100 | 100 | 100 | 100 | |
index.spec.js | 100 | 100 | 100 | 100 | |
---------------|----------|----------|----------|----------|-------------------|
Source code: https://github.com/mrdulin/mocha-chai-sinon-codelab/tree/master/src/stackoverflow/37764363