Skip to content

Commit

Permalink
testing: enforce no error or warning logs (#3097)
Browse files Browse the repository at this point in the history
* test: fix test table

* test: squash logs

* test: enforce no errors and warnings
  • Loading branch information
mcmcgrath13 authored Jan 8, 2025
1 parent 5c15209 commit 3a089b7
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 34 deletions.
3 changes: 3 additions & 0 deletions containers/ecr-viewer/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import "@testing-library/jest-dom";
import { toHaveNoViolations } from "jest-axe";
import failOnConsole from "jest-fail-on-console";
import * as matchers from "jest-extended";
import { TextEncoder } from "util";
import router from "next-router-mock";
import { clearEvaluateCache } from "@/app/view-data/utils/evaluate";

global.TextEncoder = TextEncoder;

failOnConsole();

expect.extend(toHaveNoViolations);
expect.extend(matchers);

Expand Down
8 changes: 8 additions & 0 deletions containers/ecr-viewer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions containers/ecr-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"jest-axe": "^8.0.0",
"jest-environment-jsdom": "^29.7.0",
"jest-extended": "^4.0.2",
"jest-fail-on-console": "^3.3.1",
"jest-fetch-mock": "^3.0.3",
"postcss": "^8.4.38",
"prettier": "3.1.0",
Expand Down
8 changes: 8 additions & 0 deletions containers/ecr-viewer/src/app/tests/component-utils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ describe("Metrics", () => {
const basePath = "https://example.com";
const metricOptions = { key: "value" };

jest.spyOn(console, "error").mockImplementation();

await expect(metrics(basePath, metricOptions)).rejects.toThrow(
"Sorry, we couldn't find this endpoint.",
);

expect(console.error).toHaveBeenCalledOnce();
});

it("handles internal server error", async () => {
Expand All @@ -47,8 +51,12 @@ describe("Metrics", () => {
const basePath = "https://example.com";
const metricOptions = { key: "value" };

jest.spyOn(console, "error").mockImplementation();

await expect(metrics(basePath, metricOptions)).rejects.toThrow(
"Internal Server Error",
);

expect(console.error).toHaveBeenCalledOnce();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { axe } from "jest-axe";
import { render } from "@testing-library/react";
import { act, render } from "@testing-library/react";
import EcrTable from "@/app/components/EcrTable";
import { EcrDisplay, listEcrData } from "@/app/services/listEcrDataService";
import router from "next-router-mock";
Expand Down Expand Up @@ -66,7 +66,9 @@ describe("EcrTable", () => {
filterDate: mockDateRange,
}),
);
expect(await axe(container)).toHaveNoViolations();
await act(async () => {
expect(await axe(container)).toHaveNoViolations();
});
});

it("should call listEcrDataService with all params", async () => {
Expand Down
24 changes: 14 additions & 10 deletions containers/ecr-viewer/src/app/tests/components/Encounter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ describe("Encounter", () => {
table: true,
value: (
<table>
<tr>
<th>Name</th>
<th>Role</th>
<th>Dates</th>
</tr>
<tr>
<td>Test</td>
<td>ATND</td>
<td>Start: 1/2/2023</td>
</tr>
<thead>
<tr>
<th>Name</th>
<th>Role</th>
<th>Dates</th>
</tr>
</thead>
<tbody>
<tr>
<td>Test</td>
<td>ATND</td>
<td>Start: 1/2/2023</td>
</tr>
</tbody>
</table>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,32 @@ exports[`Encounter should match snapshot 1`] = `
class="grid-col-auto width-full text-pre-line"
>
<table>
<tr>
<th>
Name
</th>
<th>
Role
</th>
<th>
Dates
</th>
</tr>
<tr>
<td>
Test
</td>
<td>
ATND
</td>
<td>
Start: 1/2/2023
</td>
</tr>
<thead>
<tr>
<th>
Name
</th>
<th>
Role
</th>
<th>
Dates
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Test
</td>
<td>
ATND
</td>
<td>
Start: 1/2/2023
</td>
</tr>
</tbody>
</table>
</div>
</div>
Expand Down

0 comments on commit 3a089b7

Please sign in to comment.