|
1 |
| -import { describe, expect, it } from "@jest/globals"; |
| 1 | +import fs from "node:fs/promises"; |
| 2 | +import { describe, expect, it, jest } from "@jest/globals"; |
2 | 3 | import isDocumentedRoute from "./isDocumentedRoute";
|
3 | 4 |
|
| 5 | +jest.mock("node:fs/promises"); |
| 6 | + |
4 | 7 | 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); |
7 | 29 | });
|
8 | 30 | });
|
0 commit comments