Skip to content

Commit

Permalink
test: improve style with Given-When-Then
Browse files Browse the repository at this point in the history
  • Loading branch information
joset98 committed Jan 28, 2025
1 parent 89ce82c commit e71330e
Showing 1 changed file with 48 additions and 26 deletions.
74 changes: 48 additions & 26 deletions utils/normalizeFilePath.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,63 @@ describe("Normalize file path tests", () => {
originalPlatform = process.platform;
});

afterAll(() => {
afterEach(() => {
// Restore original platform
Object.defineProperty(process, "platform", {
value: originalPlatform,
});
});

it("should normalize file path for Windows", () => {
Object.defineProperty(process, "platform", {
value: "win32",
describe("Given a Windows Environment", () => {
beforeEach(() => {
// Simulate Windows environment
Object.defineProperty(process, "platform", {
value: "win32",
});
});

const filePath =
"file:///C:/Users/pepe/Documents/jobus/blazer/misc/i18n-populator/test-configs/test-config.json";
const expectedPath =
"C:/Users/pepe/Documents/jobus/blazer/misc/i18n-populator/test-configs";
expect(normalizeFilePath(filePath)).toBe(expectedPath);
});
describe("When file path is provided", () => {

it("should normalize file path for Unix", () => {
Object.defineProperty(process, "platform", {
value: "linux",
it("should normalize file path", () => {
const filePath =
"file:///C:/Users/pepe/Documents/jobus/blazer/misc/i18n-populator/test-configs/test-config.json";
const expectedPath =
"C:/Users/pepe/Documents/jobus/blazer/misc/i18n-populator/test-configs";
expect(normalizeFilePath(filePath)).toBe(expectedPath);
});
})
})

describe("Given a Unix-like system", () => {
beforeEach(() => {
// Simulate Unix environment
Object.defineProperty(process, "platform", {
value: "linux",
});
});

const filePath =
"file://home/pepe/Documents/jobus/blazer/misc/i18n-populator/test-configs/test-config.json";
const expectedPath =
"home/pepe/Documents/jobus/blazer/misc/i18n-populator/test-configs";
expect(normalizeFilePath(filePath)).toBe(expectedPath);
});
describe("When File Path is provided", () => {

it("should throw an error if no string is provided", () => {
expect(() => normalizeFilePath("")).toThrow("No string provided");
});
it("should normalize file path", () => {
const filePath =
"file://home/pepe/Documents/jobus/blazer/misc/i18n-populator/test-configs/test-config.json";
const expectedPath =
"home/pepe/Documents/jobus/blazer/misc/i18n-populator/test-configs";
expect(normalizeFilePath(filePath)).toBe(expectedPath);
});
})
})

it("should handle undefined input gracefully", () => {
expect(() => normalizeFilePath(undefined)).toThrow("No string provided");
});
describe("Given any system", () => {

describe("When File Path is not valid", () => {

it("should throw an error if no string is provided", () => {
expect(() => normalizeFilePath("")).toThrow("No string provided");
});

it("should handle undefined input gracefully", () => {
expect(() => normalizeFilePath(undefined)).toThrow("No string provided");
});
})
})
});

0 comments on commit e71330e

Please sign in to comment.