0

这是我正在测试的功能:

实用程序.js

    exports.calculateAgeTimeStamp = function(timestamp) {

        //get year

        var userYear = new Date(timestamp * 1000);
        min = userYear.getFullYear();

        //get current year
        var curYear = new Date();
        max = curYear.getFullYear();

        //work out age from current year
        return Math.abs(max - min);
    }; 

它需要一个时间戳并计算年龄。

这是我的规格:

    //test to see if timestamp converts to age.
it("timestamp should be converted to age > 20503539200", function() {
    //matcher
    expect(utilities.calculateAgeTimeStamp("20503539200")).toBeNumber();
});

这是错误:

 [INFO] :   .   - timestamp should be converted to age > 20503539200 (FAILED)
    [INFO] :   .   - - TypeError: 'undefined' is not a function (evaluating 'expect(utilities.calculateAgeTimeStamp("20503539200")).toBeNumber()') in file:///Users/iPhone%20Simulator/7.1-64/Applications/F0A42483-4497-4670-AFEE-839D81C2E075/specs/lib/utilities_spec.js (line 12)
    [INFO] :   .  ============================================================
    [ERROR] :  .  THERE WERE FAILURES!
    [ERROR] :  .  ============================================================
    [ERROR] :  .  Recap of failing specs:
    [ERROR] :  .  ------------------------------------------------------------
    [ERROR] :  .  utilities timestamp should be converted to age > 20503539200. - TypeError: 'undefined' is not a function (evaluating 'expect(utilities.calculateAgeTimeStamp("20503539200")).toBeNumber()') 

我知道此功能有效,因为它在我的应用程序中运行良好。知道为什么我会收到这个错误,干杯。

4

0 回答 0