I'm trying to test my function with mocha + nyc for cheching coverage. This is function to test:
function TypeCompare(Obj){
Obj.forEach(function (el){
el.Age = StringToNumber(el.Age);
el.Name = isValidString(el.Name);
el.Surname = isValidString(el.Surname);
el.Mail = isEmail(el.Mail);
el.DateofReg = StringToDate(el.DateofReg);
el.Phone = isPhone(el.Phone);
el.Time = StringToTime(el.Time);
if(el.Age == "Age error" || el.Name == "Name/Sname error" || el.Surname == "Name/Sname error" || el.DateofReg == "Date error" || el.Time == "Time error" ||el.Mail == "Email error" || el.Phone == "Phone error"){
invalid_types.push(el);
} else {
valid_types.push(el);
}
});
RecordToDB(valid_types);
RecordToCSV(invalid_types);
}
The function getting array of objects check objects with other function for valid and push valid objects to valid_types and invalid to invalid_types. This is my testing function:
describe('Testing function TypeCompare which getting arr[objects] on input
check arr for valid and invalid objects', function () {
it('should return [valid_obj] and [] if all objects is valid', function ()
{
var arr = [{Age: '20', Name: 'Kiryl', Surname: 'Kazushchyk', Mail: 'kastys1@yandex.ru', DateofReg: '10-20-2015',
Phone: '+375257794915', Time: '10:44'},
{Age: 'fgh', Name: 'Kiryl', Surname: 'Kazushchyk', Mail: 'kastys1@yandex.ru', DateofReg: '10-20-2015',
Phone: '+375257794915', Time: '10:44'}];
app.TypeCompare(arr);
// console.log(TypeCompare.valid_types);
// console.log(TypeCompare.invalid_types);
var expected_valid = [{Age: '20', Name: 'Kiryl', Surname: 'Kazushchyk', Mail: 'kastys1@yandex.ru', DateofReg: '2015-10-20',
Phone: '+375257794915', Time: '10:44:00'}];
var expected_invalid = [{Age: 'Age error', Name: 'Kiryl', Surname: 'Kazushchyk', Mail: 'kastys1@yandex.ru', DateofReg: '2015-10-20',
Phone: '+375257794915', Time: '10:44:00'}];
assert(app.invalid_types[0].Age === expected_invalid[0].Age);
assert(app.valid_types[0].Age === expected_valid[0].Age);
});
});
I'm export this:
module.exports.TypeCompare =TypeCompare;
module.exports.valid_types = valid_types;
module.exports.invalid_types = invalid_types;
The test is passed ok, but i don't recive any information about summary: test result without coverage
If i test my other functions everything is okay:test result other functions
Can someone tell me what is the problem?
Aucun commentaire:
Enregistrer un commentaire