Skip to content

Commit 991e2cf

Browse files
committed
Add jest test for validPrUrl
1 parent 52d2104 commit 991e2cf

4 files changed

Lines changed: 2198 additions & 2 deletions

File tree

jest.config.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
};

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@
125125
},
126126
"devDependencies": {
127127
"@types/inflected": "^1.1.29",
128+
"@types/jest": "^28.1.8",
128129
"@types/react": "^17.0.3",
129-
"@types/react-dom": "^17.0.3"
130+
"@types/react-dom": "^17.0.3",
131+
"jest": "^28.1.3",
132+
"ts-jest": "^28.0.8",
133+
"typescript": "^4.7.4"
130134
}
131135
}

src/lib/validPrUrl.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { validPrUrl } from "./validPrUrl";
2+
3+
describe("validPrUrl", () => {
4+
it("successed for valid urls", () => {
5+
expect(
6+
validPrUrl("https://github.com/example/project/pull/1")
7+
).toBeTruthy();
8+
});
9+
10+
it("fails for invalid urls", () => {
11+
[
12+
"not a url",
13+
"https://anotherdomain.com/example/project/pull/1",
14+
"http://github.com/example/project/pull/1",
15+
"https://github.com/example/pull/1",
16+
"https://github.com/example/project/pulls/1",
17+
"https://github.com/example/project/pull/a",
18+
].forEach((url) => {
19+
expect(validPrUrl(url)).toBeFalsy();
20+
});
21+
});
22+
});

0 commit comments

Comments
 (0)