Skip to content

Commit d29ba92

Browse files
committed
test: isDocumentedRoute
1 parent 19c0a0d commit d29ba92

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/core/isDocumentedRoute.test.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
1-
import { describe, expect, it } from "@jest/globals";
1+
import fs from "node:fs/promises";
2+
import { describe, expect, it, jest } from "@jest/globals";
23
import isDocumentedRoute from "./isDocumentedRoute";
34

5+
jest.mock("node:fs/promises");
6+
47
describe("isDocumentedRoute", () => {
5-
it("should exist", () => {
6-
expect(typeof isDocumentedRoute).toBe("function");
8+
it("should return true if the file contains the target string", async () => {
9+
const mockFileContent = "import { handler } from '@omer-x/next-openapi-route-handler';";
10+
jest.spyOn(fs, "readFile").mockResolvedValue(mockFileContent);
11+
12+
const result = await isDocumentedRoute("some/path/to/file.ts");
13+
expect(result).toBe(true);
14+
});
15+
16+
it("should return false if the file does not contain the target string", async () => {
17+
const mockFileContent = "import someOtherLibrary from 'another-package';";
18+
jest.spyOn(fs, "readFile").mockResolvedValue(mockFileContent);
19+
20+
const result = await isDocumentedRoute("some/path/to/file.ts");
21+
expect(result).toBe(false);
22+
});
23+
24+
it("should return false if an error occurs while reading the file", async () => {
25+
jest.spyOn(fs, "readFile").mockRejectedValue(new Error("File not found"));
26+
27+
const result = await isDocumentedRoute("non/existent/path.ts");
28+
expect(result).toBe(false);
729
});
830
});

0 commit comments

Comments
 (0)