[英]How to filter out certain patterns from mocha/nyc test coverage (Node.js)?
[英]Trying to test function with mocha + nyc
我正在嘗試使用mocha + nyc測試我的功能,以了解覆蓋率。 這是要測試的功能:
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);
}
函數獲取對象數組會與其他函數一起檢查對象是否有效,並將有效對象推送到valid_types,將無效對象推送到invalid_types。 這是我的測試功能:
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);
});
});
我導出此:
module.exports.TypeCompare =TypeCompare;
module.exports.valid_types = valid_types;
module.exports.invalid_types = invalid_types;
測試通過了,可以,但是我沒有收到任何有關摘要的信息: 測試結果沒有涵蓋范圍
如果我測試其他功能,一切都還好: 測試結果其他功能
有人可以告訴我這是什么問題嗎?
解決了。 問題出在用TypeCompare調用的函數中
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.