-2
我在终端中收到错误消息Expected undefined to be greater than 18.
我创建了一个函数,并且我正在调用expect函数中的函数。我是否需要将函数作为变量传递?茉莉花单元测试 - 未定义函数
describe("Age Test", function() {
it("It calculates age and the return value must be greater than 18",
function(){
/* Define */
function ageCalculator(yDD,yMM,yYY) {
// Current date
var today = new Date();
var cDD = today.getDate();
var cMM = today.getMonth()+1; //January is 0!
var cYY = today.getFullYear();
// Difference in date
var dDD = cDD - yDD;
var dMM = cMM - yMM;
var dYY = cYY - yYY;
if (dMM < 0) {
dYY = dYY - 1;
}
if (dDD < 0) {
dMM = dMM - 1;
}
dDD = dDD - 1;
dMM = 12 + dMM;
dDD = 30 + dDD;
}
/* Run Mock */
expect(ageCalculator(27,4,1991)).toBeGreaterThan(18);
});
});
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/return – undefined