Skip to content

Commit 3c86e4e

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

11 files changed

+9058
-353
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/node_modules
2-
/build
2+
/dist

README.md

+8-2
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

+3
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

+8,990-343
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+13-3
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

+3
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

+14
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

+6
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

+7
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

+8
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+
});

tsconfig.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"include": ["src/**/*", "tests/**/*"],
3+
// "exclude": ["tests/**/*"],
24
"compilerOptions": {
35
/* Visit https://aka.ms/tsconfig to read more about this file */
46

@@ -25,7 +27,7 @@
2527
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
2628

2729
/* Modules */
28-
"module": "commonjs" /* Specify what module code is generated. */,
30+
"module": "ES6" /* Specify what module code is generated. */,
2931
// "rootDir": "./", /* Specify the root folder within your source files. */
3032
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
3133
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@@ -55,7 +57,7 @@
5557
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
5658
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
5759
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
58-
"outDir": "./build" /* Specify an output folder for all emitted files. */,
60+
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
5961
// "removeComments": true, /* Disable emitting comments. */
6062
// "noEmit": true, /* Disable emitting files from a compilation. */
6163
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
@@ -105,6 +107,5 @@
105107
/* Completeness */
106108
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
107109
"skipLibCheck": true /* Skip type checking all .d.ts files. */
108-
},
109-
"include": ["./src"]
110+
}
110111
}

0 commit comments

Comments
 (0)