Skip to content

Commit 3c86e4e

Browse files
committed
learn testing with jest, babel, and data types
1 parent c169ba6 commit 3c86e4e

File tree

11 files changed

+9058
-353
lines changed

11 files changed

+9058
-353
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/node_modules
2-
/build
2+
/dist

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# List learning typescript
22

3-
- [ ] Data types
4-
- [ ] Testing
3+
- [x] Setup Typescript
4+
- [x] Unit test with [Jest](https://jestjs.io/)
5+
- [x] Agar jest support JS Module, maka install [Babel](https://babeljs.io/)
56
- [x] Union
67
- [x] Intersection
8+
- [x] Ubah JS Module di tsconfig.json
9+
- [x] Testing with Jest
10+
- [ ] a
11+
- [ ] a
12+
- [ ] a
713

babel.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env", "@babel/preset-typescript"]
3+
}

package-lock.json

Lines changed: 8990 additions & 343 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,23 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"tsc": "rm -rf build/ && tsc",
8-
"ts": "rm -rf build/ && tsc -w",
9-
"dev": "nodemon ./build/latihan.js"
7+
"test": "jest"
8+
},
9+
"jest": {
10+
"transform": {
11+
"^.+\\.[t|j]sx?$": "babel-jest"
12+
}
1013
},
1114
"author": "zaiinhs",
1215
"license": "ISC",
1316
"devDependencies": {
17+
"@babel/preset-env": "^7.22.20",
18+
"@babel/preset-typescript": "^7.22.15",
19+
"@jest/globals": "^29.7.0",
20+
"@types/jest": "^29.5.5",
21+
"babel-jest": "^29.7.0",
22+
"jest": "^29.7.0",
23+
"ts-jest": "^29.1.1",
1424
"typescript": "^5.2.2"
1525
},
1626
"dependencies": {

src/say-hello.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function sayHello(name: string): string {
2+
return `Hello ${name}`;
3+
}

tests/array.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
describe("Array", function () {
2+
it("should array", function () {
3+
const names: string[] = ["zain", "abidin", "zainal"];
4+
const values: number[] = [1, 2, 3, 4, 5];
5+
});
6+
7+
it("should support readonly array", function () {
8+
const hobbies: ReadonlyArray<string> = ["Membaca", "Menulis"];
9+
});
10+
11+
it("should support tuple", function () {
12+
const person: readonly [string, string, number] = ["zainl", "abidin", 23];
13+
});
14+
});

tests/hello.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe("hello", function () {
2+
it("zain", function () {
3+
const name = "Hello zain";
4+
expect(name).toBe("Hello zain");
5+
});
6+
});

tests/say-hello.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { sayHello } from "../src/say-hello";
2+
3+
describe("sayHello", function (): void {
4+
it("should return hello zain", function (): void {
5+
expect(sayHello("zain")).toBe("Hello zain");
6+
});
7+
});

tests/tipe-data.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
describe("Data Type", function () {
2+
it("should must declare"),
3+
function () {
4+
const name: string = "Zainal Abidin";
5+
const balance: number = 1000;
6+
const isVip: boolean = true;
7+
};
8+
});

0 commit comments

Comments
 (0)