Reputation: 11
I am new to JavaScript/JavaScript testing and was doing a course on mocha test framework with chai. how to test simple CRUD application? I want to write unit tests for all of them. I tried looking at questions here, but all of them were very advanced and i did not understand them. can you please help me it would be appreciated. the question was
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
}
}
Upvotes: 1
Views: 352
Reputation: 790
In my code crud.js is the file of the above code as you have mentioned.
var assert = require('assert');
var crud = require('../crud');
describe('Crud application', function() {
it('addDetails()', function () {
assert.deepStrictEqual(crud.addDetails(), ['one']);
});
it('deleteDetails()', function () {
assert.equal(crud.deleteDetails(), 'two');
});
it('editDetails()', function () {
assert.deepStrictEqual(crud.editDetails(), [ 'one', 0, 1, 'three' ]);
});
it('updateDetails()', function () {
assert.deepStrictEqual(crud.updateDetails(), [ 'one', 'three', 1, 0, 'two' ]);
});
it('detailsPop()', function () {
assert.deepStrictEqual(crud.detailsPop(), ['one', 'two', 'one']);
});
it('concatData()', function () {
assert.deepStrictEqual(crud.concatData(), ["one", "two"]);
});
});
Upvotes: 0