mirror of
https://github.com/Kir-Antipov/mc-publish.git
synced 2024-11-27 10:51:03 -05:00
43 lines
1.5 KiB
TypeScript
43 lines
1.5 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("does not throw error if file exists", () => {
|
||
|
expect(() => FileNotFoundError.throwIfNotFound("test")).not.toThrow();
|
||
|
});
|
||
|
});
|
||
|
});
|