mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-23 00:40:59 -05:00
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { FileNotFoundError } from "@/utils/errors/file-not-found-error";
|
|
import mockFs from "mock-fs";
|
|
|
|
describe("FileNotFoundError", () => {
|
|
describe("constructor", () => {
|
|
test("initializes with default message if none provided", () => {
|
|
const error = new FileNotFoundError("test.txt");
|
|
|
|
expect(error).toBeInstanceOf(FileNotFoundError);
|
|
expect(error.name).toBe("FileNotFoundError");
|
|
expect(error.message).toBe("Could not find file 'test.txt'.");
|
|
expect(error.fileName).toBe("test.txt");
|
|
});
|
|
|
|
test("initializes with provided message", () => {
|
|
const error = new FileNotFoundError("test.txt", "Custom error message");
|
|
|
|
expect(error).toBeInstanceOf(FileNotFoundError);
|
|
expect(error.name).toBe("FileNotFoundError");
|
|
expect(error.message).toBe("Custom error message");
|
|
expect(error.fileName).toBe("test.txt");
|
|
});
|
|
});
|
|
|
|
describe("throwIfNotFound", () => {
|
|
beforeEach(() => {
|
|
mockFs({ test: "test" });
|
|
});
|
|
|
|
afterEach(() => {
|
|
mockFs.restore();
|
|
});
|
|
|
|
test("throws error if file does not exist", () => {
|
|
expect(() => FileNotFoundError.throwIfNotFound("test.txt")).toThrow(FileNotFoundError);
|
|
});
|
|
|
|
test("throws a FileNotFoundError with the provided error message", () => {
|
|
expect(() => FileNotFoundError.throwIfNotFound("test.txt", "I don't like file extensions.")).toThrowError(new FileNotFoundError("test.txt", "I don't like file extensions."));
|
|
});
|
|
|
|
test("does not throw error if file exists", () => {
|
|
expect(() => FileNotFoundError.throwIfNotFound("test")).not.toThrow();
|
|
});
|
|
});
|
|
});
|