1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-30 13:58:08 +00:00

create jest

This commit is contained in:
Nebel 2021-04-13 18:37:49 +09:00
parent b532b3b3ea
commit 98b4ecf114
8 changed files with 3733 additions and 0 deletions

1
jest/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/coverage/

55
jest/README.md Normal file
View file

@ -0,0 +1,55 @@
## 何をしたかったか
Jest でカバレッジを取ると行単位で結果が得られるが三項演算子などで 1 行に条件分岐があるときどうなるか検証したかった
## 結果
foo.test.js:
```js
import foo from "./foo.js";
test("positive number", () => {
expect(foo(1)).toBe(1);
});
test("negative number", () => {
expect(foo(-1)).toBe(0);
});
```
```
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
add.js | 100 | 100 | 100 | 100 |
foo.js | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------
```
foo.test.js:
```js
import foo from "./foo.js";
test("positive number", () => {
expect(foo(1)).toBe(1);
});
// test("negative number", () => {
// expect(foo(-1)).toBe(0);
// });
```
```
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 100 | 50 | 100 | 100 |
add.js | 100 | 100 | 100 | 100 |
foo.js | 100 | 50 | 100 | 100 | 2
----------|---------|----------|---------|---------|-------------------
```
パスを 1 つコメントアウトするとステートメントや関数、行数は 100 %のまま、Branch が 50 % になった。

5
jest/add.js Normal file
View file

@ -0,0 +1,5 @@
function add(a, b) {
return a + b;
}
export default add;

5
jest/add.test.js Normal file
View file

@ -0,0 +1,5 @@
import add from "./add.js";
test("add", () => {
expect(add(1, 2)).toBe(3);
});

5
jest/foo.js Normal file
View file

@ -0,0 +1,5 @@
function foo(n) {
return n > 0 ? n : 0;
}
export default foo;

9
jest/foo.test.js Normal file
View file

@ -0,0 +1,9 @@
import foo from "./foo.js";
test("positive number", () => {
expect(foo(1)).toBe(1);
});
// test("negative number", () => {
// expect(foo(-1)).toBe(0);
// });

14
jest/package.json Normal file
View file

@ -0,0 +1,14 @@
{
"name": "jest",
"version": "1.0.0",
"main": "index.js",
"type": "module",
"author": "Kohei Watanabe <kou029w@gmail.com>",
"license": "MIT",
"scripts": {
"test": "NODE_OPTIONS=--experimental-vm-modules jest --coverage"
},
"devDependencies": {
"jest": "^26.6.3"
}
}

3639
jest/yarn.lock Normal file

File diff suppressed because it is too large Load diff