Skip to content

Commit

Permalink
test(urlUtils): add unit tests for getEnvironmentDependentUrl function
Browse files Browse the repository at this point in the history
  • Loading branch information
amalv committed Jan 15, 2024
1 parent be14d88 commit 231586b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/utils/urlUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { getEnvironmentDependentUrl } from "./urlUtils";

describe("getEnvironmentDependentUrl", () => {
const originalWindowLocation = window.location;

beforeEach(() => {
delete window.location;

Check failure on line 7 in src/utils/urlUtils.test.ts

View workflow job for this annotation

GitHub Actions / build

The operand of a 'delete' operator must be optional.
window.location = { ...originalWindowLocation };
});

afterEach(() => {
vi.unstubAllEnvs();

Check failure on line 12 in src/utils/urlUtils.test.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'vi'.
});

it("returns the correct URL for production environment", () => {
vi.stubEnv("VITE_ENV", "production");

Check failure on line 16 in src/utils/urlUtils.test.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'vi'.
window.location.origin = "https://amalv.github.io";

Check failure on line 17 in src/utils/urlUtils.test.ts

View workflow job for this annotation

GitHub Actions / build

Cannot assign to 'origin' because it is a read-only property.

const url = getEnvironmentDependentUrl();

expect(url).toBe("https://amalv.github.io/bukie");
});

it("returns the correct URL for non-production environment", () => {
vi.stubEnv("VITE_ENV", "development");

Check failure on line 25 in src/utils/urlUtils.test.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'vi'.
window.location.origin = "http://localhost:3000";

Check failure on line 26 in src/utils/urlUtils.test.ts

View workflow job for this annotation

GitHub Actions / build

Cannot assign to 'origin' because it is a read-only property.

const url = getEnvironmentDependentUrl();

expect(url).toBe("http://localhost:3000");
});
});

0 comments on commit 231586b

Please sign in to comment.