UNPKG

eslint-plugin-file-export-name

Version:

ESLint plugin to enforce matching file names with default export names.

61 lines (50 loc) 2.01 kB
const { convertToCase, matchPattern } = require("../src/utils.cjs"); describe("convertToCase", () => { describe("pascal case", () => { test("converts kebab case to pascal case", () => { expect(convertToCase("my-component", "pascal")).toBe("MyComponent"); }); test("converts snake case to pascal case", () => { expect(convertToCase("my_component", "pascal")).toBe("MyComponent"); }); }); describe("camel case", () => { test("converts kebab case to camel case", () => { expect(convertToCase("my-component", "camel")).toBe("myComponent"); }); test("converts snake case to camel case", () => { expect(convertToCase("my_component", "camel")).toBe("myComponent"); }); }); describe("kebab case", () => { test("converts pascal case to kebab case", () => { expect(convertToCase("MyComponent", "kebab")).toBe("my-component"); }); test("converts camel case to kebab case", () => { expect(convertToCase("myComponent", "kebab")).toBe("my-component"); }); }); describe("snake case", () => { test("converts pascal case to snake case", () => { expect(convertToCase("MyComponent", "snake")).toBe("my_component"); }); test("converts camel case to snake case", () => { expect(convertToCase("myComponent", "snake")).toBe("my_component"); }); }); test("throws error for unknown case type", () => { expect(() => convertToCase("test", "unknown")).toThrow("Unknown case type: unknown"); }); }); describe("matchPattern", () => { test("matches pattern correctly", () => { const pattern = /^Test.*$/; expect(matchPattern(pattern, "TestComponent")).toBe(true); expect(matchPattern(pattern, "OtherComponent")).toBe(false); }); test("matches complex patterns", () => { const pattern = /^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/; // PascalCase pattern expect(matchPattern(pattern, "MyComponent")).toBe(true); expect(matchPattern(pattern, "myComponent")).toBe(false); }); });