Reputation: 243
I'm using nodeJS and have created unit tests using sinon,chai along with code coverage nyc. but nyc is returning 0% for statements, lines, functions -
======================== Coverage summary ===============================
Statements : 0% ( 0/34 ) Branches : 100% ( 0/0 ) Functions : 0% ( 0/4 ) Lines : 0% ( 0/34 )
app.js -
exports.get = async (event, context) => {
try {
const data = await getResult(13, 'table', 'inbox', false, 2);
return success(data);
} catch (err) {
return failure({ status: false });
}
};
app.test.unit.js
const sandbox = sinon.createSandbox();
const expect = chai.expect;
let event, context;
describe('test get', () => {
afterEach(() => {
sandbox.restore();
});
it('get should return success', async () => {
// Mock
const result = { };
sandbox.stub(lambda, 'getResult').returns(result);
// Act
let response = await get(event, context);
expect(response.statusCode).equal(200);
});
it('get should return failure', async () => {
sandbox.stub(lambda, 'getResult').throws(new Error('whatever'));
// Act
let response = await get(event, context);
console.log(response.body);
//Expect
expect(response.statusCode).equal(500);
});
});
Upvotes: 0
Views: 890