Skip to content

Commit

Permalink
feat: add tests for url utils
Browse files Browse the repository at this point in the history
  • Loading branch information
totraev committed Sep 12, 2024
1 parent 6d75900 commit bfb673c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/url.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const URL_REGEX = /^https?:\/\//;
const URL_REGEX = /^https:\/\//;

export function isValidUrl(url: string) {
return URL_REGEX.test(url);
Expand Down
23 changes: 23 additions & 0 deletions tests/utils/url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { isValidUrl } from "@/utils/url";

describe("isValidUrl", () => {
it("should mark url with https protocol as valid", () => {
const url = "https://babylonlabs.io/";
expect(isValidUrl(url)).toBeTruthy();
});

it("should mark url with http protocol as invalid", () => {
const url = "http://babylonlabs.io/";
expect(isValidUrl(url)).toBeFalsy();
});

it("should mark url without protocol as invalid", () => {
const url = "babylonlabs.io/";
expect(isValidUrl(url)).toBeFalsy();
});

it("should mark empty string as invalid url", () => {
const url = "";
expect(isValidUrl(url)).toBeFalsy();
});
});

0 comments on commit bfb673c

Please sign in to comment.