【问题标题】:Jasmine unit testing - undefined function茉莉花单元测试 - 未定义的功能
【发布时间】:2016-03-07 13:32:37
【问题描述】:

我在终端 Expected undefined to be greater than 18. 中收到错误消息我已经创建了一个函数,并且我正在调用函数中的期望函数。我需要将函数作为变量传递吗?

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

【问题讨论】:

标签: javascript unit-testing jasmine


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-07-17
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    • 2020-11-25
    相关资源
    最近更新 更多