2016-03-07 84 views
-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); 
    }); 
}); 
+0

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/return – undefined

回答

2

你不從功能,因此ageCalculator(27,4,1991)調用的結果是undefined返回任何東西。