index .js
module.exports = {
addDetails: function() {
let data =[]
data.push("one");
return data
},
deleteDetails: function() {
let data =["one" , "two"]
data.splice(0 , 1)
return data
},
editDetails: function() {
let data =["one"]
data.splice(0 , 1 , "three")
return data
},
updateDetails: function() {
let data = ["one" , "three"]
data.splice(1 , 0 , "two")
return data
},
detailsPop: function() {
let numb = ["one" , "two"]
numb.pop()
return numb
},
concatData: function() {
let data1 = ["one"]
let data2 = ["two"]
let result = data1.concat(data2)
return result
}
}
indextest.js
var assert = require("assert");
var crud = require('../src/index');
describe('Crud application', ()=>{
//write your code here
it('should add "one" to the array', async() => {
const result = await crud.addDetails();
assert.deepEqual(result, ['one']);
});
it('should delete the first element from the array', async() => {
const result = await crud.deleteDetails();
assert.deepEqual(result, ['two']);
console.log(2)
});
it('should replace "one" with "three" in the array', async() => {
const result = await crud.editDetails();
assert.deepEqual(result, ['three']);
});
it('should update the array with "two" between "one" and "three"', async() => {
const result = await crud.updateDetails();
assert.deepEqual(result, ['one', 'two', 'three']);
});
it('should remove the last element from the array', async() => {
const result = await crud.detailsPop();
assert.deepEqual(result, ['one']);
});
it('should concatenate two arrays', async() => {
const result = await crud.concatData();
assert.deepEqual(result, ['one', 'two']);
});
it("Don't remove this dummy test case as its required for validation", async() => {
const dummy = [{}];
dummy.should.have.length(1);
});
});
mocha --timeout 10000 --reporter mocha-junit-reporter --collectCoverageFrom=src/index.js --exit
The test code always fails by saying
mocha --timeout 10000 --reporter mocha-junit-reporter --collectCoverageFrom=src/index.js --exit
Error :
(node:2059) UnhandledPromiseRejectionWarning: TypeError: Cannot convert undefined or null to object