0

Here is the function I am testing:

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

It takes a timestamp and calculates age.

Here is my spec:

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

Here is the error:

 [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()') 

I know this function works, because it is working fine in my app. Any idea why I am getting this error, cheers.

user3754111
  • 859
  • 1
  • 10
  • 20
  • 2
    How is utilities defined? – pgreen2 Jul 10 '14 at 21:08
  • 1
    One of the following is true: A) `utilities` is not what you think it is. B) The matcher `toBeNumber` is mis-spelled. C) The matcher is not being loaded. Which of these three is the issue cannot be gleaned from what we have here. – Sean Vieira Jul 10 '14 at 21:09
  • https://github.com/JamieMason/Jasmine-Matchers toBeNumber seems to be a function here(unless I am mistaken). And utilities is the file which stores the function calculateAgeTimeStamp – user3754111 Jul 10 '14 at 21:27
  • just edited my OP, cheers. – user3754111 Jul 10 '14 at 21:28
  • Have you included Utilities.js in your config so that the file is loaded? – oldwizard Oct 12 '14 at 20:00

0 Answers0