Emmanuel Ani
Emmanuel Ani

Reputation: 121

Fixing logical error when testing with describe in Jasmine?

I am trying to test the following and I get an error:

enter image description here

dateUtil.spec.ts:

import { isDay } from "./dateUtil";

describe("utils/dateUtil", () => {
  describe("isDate", () => {
    it("should determine if time of day is day or night", () => {
      const day = "Tue Dec 18 2018 12:00:00 GMT-0800 (Pacific Standard Time)";
      const night = "Tue Dec 18 2018 20:00:00 GMT-0800 (Pacific Standard Time)";

      expect(isDay(new Date(day))).toBeTruthy();
      expect(isDay(new Date(night))).toBeFalsy();
    });
  });
});

dateUtil.ts

export const isDay = (date: Date) => {
    const currentHour = date.getHours();
    return currentHour > 6 && currentHour < 18;
};

What am I missing and what do I need to do?

Upvotes: 1

Views: 92

Answers (1)

Emmanuel Ani
Emmanuel Ani

Reputation: 121

Change time according to time zone. For example:

const night = "Sun Oct 04 2020 10:23:31 GMT+0100 (West Africa Standard Time)";

Upvotes: 1

Related Questions