Mock date constructor with Jasmine

后端 未结 5 1805
轮回少年
轮回少年 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:30

    from jasmine example,

    jasmine.clock().install();
    var baseTime = new Date(2013, 9, 23);
    jasmine.clock().mockDate(baseTime);
    jasmine.clock().tick(50)
    expect(new Date().getTime()).toEqual(baseTime.getTime() + 50);
    
    
    afterEach(function () {
        jasmine.clock().uninstall();
    });
    

    jasmine date

提交回复
热议问题