简体   繁体   English

Jasmine 单元测试 - 未定义的函数

[英]Jasmine unit testing - undefined function

I'm getting error message in terminal Expected undefined to be greater than 18. I've created a function and i'm calling the function in expect function.我在终端中收到错误消息Expected undefined to be greater than 18.我创建了一个函数,我正在调用该函数。 Do I need to pass function as a variable?我需要将函数作为变量传递吗?

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);
    });
});

您不会从函数返回任何内容,因此ageCalculator(27,4,1991)调用的结果是undefined

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM