Mock date constructor with Jasmine

后端 未结 5 1807
轮回少年
轮回少年 2021-01-07 16:46

I\'m testing a function that takes a date as an optional argument. I want to assert that a new Date object is created if the function is called without the argument.

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 17:34

    for me it worked with:

    spyOn(Date, 'now').and.callFake(function() {
        return _currdate;
      });
    

    instead of .andCallFake (using "grunt-contrib-jasmine": "^0.6.5", that seems to include jasmine 2.0.0)

提交回复
热议问题