簡體   English   中英

Jasmine 單元測試 - 未定義的函數

[英]Jasmine unit testing - undefined function

我在終端中收到錯誤消息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);
    });
});

您不會從函數返回任何內容,因此ageCalculator(27,4,1991)調用的結果是undefined

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM