Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
9sneha-n committed Jan 2, 2024
1 parent e24e9ce commit 02d33b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/webapp/pages/app/__tests__/App.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getAdminTestContext, getHospitalDataEntryTestContext } from "../../../.
import { Provider } from "@dhis2/app-runtime";
import { CurrentModuleContext } from "../../../contexts/current-module-context";
import { createModuleList } from "../../../../domain/entities/__tests__/moduleFixtures";
import { Worker } from "./workerMock";

describe("App", () => {
beforeAll(() => {
Expand All @@ -17,6 +18,8 @@ describe("App", () => {
removeListener: function () {},
};
};

window.Worker = window.Worker || new Worker("");
});

it("renders the feedback component", async () => {
Expand Down
27 changes: 27 additions & 0 deletions src/webapp/pages/app/__tests__/workerMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { noop } from "@vitest/utils";

export class Worker {
url: string | URL;
onmessage: any;
onmessageerror: any;
onerror: any;
addEventListener: any;
terminate: any;
removeEventListener: any;
dispatchEvent: any;

constructor(scriptURL: string | URL) {
this.url = scriptURL;
this.onmessage = noop;
this.onmessageerror = noop;
this.onerror = noop;
}
postMessage(msg: string): void {
this.onmessage(msg);
}
}

Object.defineProperty(window, "Worker", {
writable: true,
value: Worker,
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { render } from "@testing-library/react";
import { getAdminTestContext } from "../../../../utils/tests";
import { Provider } from "@dhis2/app-runtime";
import App from "../../app/App";
import { Worker } from "../../app/__tests__/workerMock";

describe("Survey List Page", () => {
beforeAll(async () => {
Expand All @@ -16,7 +17,7 @@ describe("Survey List Page", () => {
removeListener: function () {},
};
};

window.Worker = window.Worker || new Worker("");
//navigate to survey list page
const view = getView();
const ppsSurveysButton = await view.findByRole("button", {
Expand Down

0 comments on commit 02d33b3

Please sign in to comment.