Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: quiet console.error in passing api.test.ts #202

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export default tseslint.config(
"@typescript-eslint/no-empty-function": "off",
// expect.any is untyped and triggers this all the time.
"@typescript-eslint/no-unsafe-assignment": "off",
// sometimes the easiest way to mock a complex test setup is to mutate something
"better-mutation/no-mutation": "off",
/* we do `view = render(); view.getBy()` which also doesn't require destructuring
and has less global mutable state than `screen`. */
"testing-library/prefer-screen-queries": "off",
Expand Down
20 changes: 17 additions & 3 deletions js/test/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ describe("get", () => {
});

describe("useApiResult", () => {
let spyConsoleError: jest.SpiedFunction<typeof console.error>;
beforeEach(() => {
spyConsoleError = jest.spyOn(console, "error");
});
afterEach(() => {
spyConsoleError.mockRestore();
});

test("returns loading state", () => {
const RawData = z.string();
const parser = (s: string) => s;
Expand Down Expand Up @@ -167,8 +175,10 @@ describe("useApiResult", () => {
const RawData = z.string();
const parser = (s: string) => s;

const { promise, resolve } = PromiseWithResolvers<Response>();
// this test triggers console.error. quiet it.
spyConsoleError.mockImplementationOnce(() => {});

const { promise, resolve } = PromiseWithResolvers<Response>();
jest.mocked(fetch).mockReturnValue(promise);

const { result } = renderHook(useApiResult, {
Expand All @@ -192,8 +202,10 @@ describe("useApiResult", () => {
const RawData = z.string();
const parser = (s: string) => s;

const { promise, resolve } = PromiseWithResolvers<Response>();
// this test triggers console.error. quiet it.
spyConsoleError.mockImplementationOnce(() => {});

const { promise, resolve } = PromiseWithResolvers<Response>();
jest.mocked(fetch).mockReturnValue(promise);

const { result } = renderHook(useApiResult, {
Expand All @@ -218,8 +230,10 @@ describe("useApiResult", () => {
const RawData = z.string();
const parser = (s: string) => s;

const { promise, resolve } = PromiseWithResolvers<Response>();
// this test triggers console.error. quiet it.
spyConsoleError.mockImplementationOnce(() => {});

const { promise, resolve } = PromiseWithResolvers<Response>();
jest.mocked(fetch).mockReturnValue(promise);

const { result } = renderHook(useApiResult, {
Expand Down
1 change: 0 additions & 1 deletion js/test/helpers/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable better-mutation/no-mutation */
import { MetaDataKey } from "../../util/metadata";

export const putMetaData = (key: MetaDataKey, value: string) => {
Expand Down
2 changes: 0 additions & 2 deletions js/test/helpers/promiseWithResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ export const PromiseWithResolvers = <T>(): {
let resolve: ((value: T | PromiseLike<T>) => void) | undefined = undefined;
let reject: ((reason?: unknown) => void) | undefined = undefined;
const promise = new Promise<T>((res, rej) => {
// eslint-disable-next-line better-mutation/no-mutation
resolve = res;
// eslint-disable-next-line better-mutation/no-mutation
reject = rej;
});

Expand Down
Loading