Skip to content

Commit

Permalink
Use timezone-mock for handling test timezones in jest
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Dec 9, 2024
1 parent 83f06ee commit ff6add0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"sass-loader": "^13.3.2",
"store": "^2.0.12",
"style-loader": "^3.3.3",
"timezone-mock": "^1.3.6",
"ts-jest": "^29.2.3",
"ts-loader": "^9.5.0",
"tsconfig-paths-webpack-plugin": "^4.1.0",
Expand Down
6 changes: 4 additions & 2 deletions client/src/utils/dates.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import MockDate from "timezone-mock";

import { formatGalaxyPrettyDateString, galaxyTimeToDate, localizeUTCPretty } from "./dates";

describe("dates.ts", () => {
beforeEach(() => {
process.env.TZ = "America/New_York";
MockDate.register("Etc/GMT+4");
});

afterEach(() => {
delete process.env.TZ;
MockDate.unregister();
});

describe("galaxyTimeToDate", () => {
Expand Down
5 changes: 5 additions & 0 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11381,6 +11381,11 @@ timers-browserify@^2.0.12:
dependencies:
setimmediate "^1.0.4"

timezone-mock@^1.3.6:
version "1.3.6"
resolved "https://registry.yarnpkg.com/timezone-mock/-/timezone-mock-1.3.6.tgz#44e4c5aeb57e6c07ae630a05c528fc4d9aab86f4"
integrity sha512-YcloWmZfLD9Li5m2VcobkCDNVaLMx8ohAb/97l/wYS3m+0TIEK5PFNMZZfRcusc6sFjIfxu8qcJT0CNnOdpqmg==

[email protected]:
version "1.0.5"
resolved "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz"
Expand Down

0 comments on commit ff6add0

Please sign in to comment.