refactor: improve code readability by normalizing whitespace and enhancing comments in tests

This commit is contained in:
Nawaz Dhandala
2025-12-16 20:35:34 +00:00
parent 9c3d21fec4
commit 8998faac57
5 changed files with 22 additions and 18 deletions

View File

@@ -488,8 +488,10 @@ describe("BaseAPI", () => {
});
it("should use DEFAULT_LIMIT when limit is 0 (falsy value fallback)", async () => {
// When limit is 0, parseInt("0", 10) returns 0 which is falsy,
// so the code falls back to DEFAULT_LIMIT via || operator
/*
* When limit is 0, parseInt("0", 10) returns 0 which is falsy,
* so the code falls back to DEFAULT_LIMIT via || operator
*/
emptyRequest.query["limit"] = "0";
// This should NOT throw since limit=0 is converted to DEFAULT_LIMIT
await expect(

View File

@@ -304,8 +304,12 @@ PARTITION BY (column_ObjectID)
/* eslint-enable prettier/prettier */
// Normalize whitespace for comparison to avoid formatting issues
const normalizeWhitespace = (s: string): string => s.replace(/\s+/g, ' ').trim();
expect(normalizeWhitespace(statement.query)).toBe(normalizeWhitespace(expectedStatement.query));
const normalizeWhitespace = (s: string): string => {
return s.replace(/\s+/g, " ").trim();
};
expect(normalizeWhitespace(statement.query)).toBe(
normalizeWhitespace(expectedStatement.query),
);
expect(statement.query_params).toStrictEqual(
expectedStatement.query_params,
);

View File

@@ -2,12 +2,7 @@ import FilePicker from "../../../UI/Components/FilePicker/FilePicker";
import ModelAPI from "../../../UI/Utils/ModelAPI/ModelAPI";
import { describe, expect, beforeEach, jest } from "@jest/globals";
import "@testing-library/jest-dom/extend-expect";
import {
fireEvent,
render,
screen,
waitFor,
} from "@testing-library/react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import HTTPResponse from "../../../Types/API/HTTPResponse";
import MimeType from "../../../Types/File/MimeType";
import ObjectID from "../../../Types/ObjectID";
@@ -68,10 +63,7 @@ const mockCreateResponse: MockCreateResponseFunction = async (
return new HTTPResponse(200, fileModel as any, {});
};
type MockFileModelFunction = (
file: File,
id?: string,
) => Promise<FileModel>;
type MockFileModelFunction = (file: File, id?: string) => Promise<FileModel>;
const mockFileModel: MockFileModelFunction = async (
file: File,
@@ -457,7 +449,7 @@ describe("FilePicker", () => {
});
// Error on arrayBuffer test
it('should handle error when file arrayBuffer fails', async () => {
it("should handle error when file arrayBuffer fails", async () => {
const file: File = mockFile("error-file.png");
file.arrayBuffer = getJestMockFunction().mockRejectedValue(
new Error("File too large"),

View File

@@ -402,7 +402,11 @@ describe("API.patch", () => {
test("should make a PATCH request", async () => {
mockedAxios.mockResolvedValueOnce(createAxiosResponse());
const url: URL = new URL(Protocol.HTTPS, "catfact.ninja", new Route("fact"));
const url: URL = new URL(
Protocol.HTTPS,
"catfact.ninja",
new Route("fact"),
);
const got: HTTPResponse<JSONObject> = await API.patch({
url,
data: requestData,

View File

@@ -1,5 +1,7 @@
// AI Template definitions for different note types
// These templates guide AI generation for various use cases
/*
* AI Template definitions for different note types
* These templates guide AI generation for various use cases
*/
export interface AITemplate {
id: string;