Fred2020
Fred2020

Reputation: 495

Is it possible to mock a Date in Javascript?

Is it possible to mock the Date returned from this service so that it can reflect different timezones in a Jasmine/Karma context? I'm not looking to simplify modify the hours/minutes to reflect UTC, the offset will be modified too. The mock object will behave as if new Date() was created from a browser in that timezone.

export class TimeService {
  static getCurrentDate(): Date {
    return new Date();
  }
}

Upvotes: 0

Views: 37

Answers (0)

Related Questions