Fixing logical error when testing with describe in Jasmine?

676
1
Jump to solution
10-04-2020 02:02 AM
EmmanuelAni
New Contributor II

I get this error when running tests for an application. Here is the test:

dateUtil.ts

```

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

```

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();
});
});
});

```

What am I getting wrong?

0 Kudos
1 Solution

Accepted Solutions
EmmanuelAni
New Contributor II

I found out that the date makes a time shift according to your machine's time zone. Change the test date accordingly, e.g. 'Sun Oct 04 2020 10:23:31 GMT+0100 (West Africa Standard Time)'

View solution in original post

0 Kudos
1 Reply
EmmanuelAni
New Contributor II

I found out that the date makes a time shift according to your machine's time zone. Change the test date accordingly, e.g. 'Sun Oct 04 2020 10:23:31 GMT+0100 (West Africa Standard Time)'

0 Kudos