Skip to content

Commit

Permalink
Use fake timers in all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Aug 19, 2023
1 parent 23458ab commit 739c4d0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
9 changes: 7 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ const config = {
],
},
testMatch: [isTestFile ? "**/*.spec.ts" : "<rootDir>/test/**/*.spec.*"],
resetMocks: true,
collectCoverageFrom: ["<rootDir>/src/**/*"],
coverageDirectory: "artifacts/coverage/jest",
collectCoverageFrom: ["<rootDir>/src/**/*"],

resetMocks: true,
fakeTimers: {
advanceTimers: true,
enableGlobally: true,
},
};

export default config;
22 changes: 12 additions & 10 deletions test/jest/geolocation/get-current-position.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ describe("Geolocation.getCurrentPosition()", () => {
let errorCallback: jest.Mock;

beforeEach(() => {
jest.setSystemTime(111);

successCallback = jest.fn();
errorCallback = jest.fn();
});
Expand Down Expand Up @@ -287,7 +289,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("calls the success callback with the position", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});

Expand Down Expand Up @@ -323,7 +325,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("does not include the time spent waiting for permission in the timeout", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 131,
});
});
});
Expand Down Expand Up @@ -401,7 +403,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("uses the response from the original handler", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});
});
Expand Down Expand Up @@ -429,7 +431,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("uses the response from the newly-added handler", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});
});
Expand Down Expand Up @@ -461,7 +463,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("uses the response from the original handler", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});
});
Expand Down Expand Up @@ -493,7 +495,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("uses the response from the newly-added handler", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});
});
Expand Down Expand Up @@ -681,7 +683,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("calls the success callback with the position", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});

Expand All @@ -707,7 +709,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("calls the success callback with the new position", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsB,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});

Expand Down Expand Up @@ -737,7 +739,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("calls the success callback with the position", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});
});
Expand Down Expand Up @@ -913,7 +915,7 @@ describe("Geolocation.getCurrentPosition()", () => {
it("calls the success callback with the position", () => {
expect(successCallback).toHaveBeenCalledWith({
coords: coordsA,
timestamp: expect.any(Number) as number,
timestamp: 111,
});
});

Expand Down

0 comments on commit 739c4d0

Please sign in to comment.