Mocking dates in AngularJS / Jasmine tests

后端 未结 4 1373
一个人的身影
一个人的身影 2021-02-05 01:19

I have a directive that initializes the Date object several times in several functions. When Unit testing the individual functions I can handle stubbing the date like this:

4条回答
  •  终归单人心
    2021-02-05 01:52

    angular.mock.TzDate would a better native alternative here. this comes as a helper from angular mocks and truly safe guard your test from the system timezone or any other dependencies

    https://docs.angularjs.org/api/ngMock/type/angular.mock.TzDate

    this plays well with Jasmine or mocha

提交回复
热议问题