0 votes
in AngularJS Packaging and Testing by
How to mock the date using Jasmine?

1 Answer

0 votes
by
The current date can also be mocked with the Jasmine Clock. If you don't give mockDate a base time, it will use the current date.

describe("Mocking the Date object", function(){

    it("mocks the Date object and sets to time", function() {

      var baseTime = new Date(2021, 9, 25);

¶

If you do not provide a base time to mockDate it will use the current date.

      jasmine.clock().mockDate(baseTime);

      jasmine.clock().tick(50);

      expect(new Date().getTime()).toEqual(baseTime.getTime() + 50);

    });

  });

});

Related questions

0 votes
asked Aug 20, 2021 in AngularJS Packaging and Testing by SakshiSharma
0 votes
asked Aug 19, 2021 in AngularJS Packaging and Testing by SakshiSharma
...