Skip to content

Commit

Permalink
♻️ 【第1章 仮実装】Dollar クラスを作成しコンパイルエラーを解消する
Browse files Browse the repository at this point in the history
<テスト駆動開発(TDD)の流れ>
✅ 1. まずはテストを1つ書く
✅ 2. すべてのテストを走らせ、新しいテストの失敗を確認する
 3. 小さな変更を行う
 4. すべてのテストを走らせ、すべて成功することを確認する
 5. リファクタリングを行って重複を除去する

・以下の問題点があるのでこれを解消しコンパイルを通す
 ・Dollarクラスがない
 ・コンストラクタがない
 ・times メソッドがない
 ・amount フィールドが無い
・テストを実行するとコンパイルエラーは解消され、テストに失敗することを確認できる

```
/usr/src # yarn run test src/__tests__/dollar.test.ts
 FAIL  src/__tests__/dollar.test.ts
  ✕ times (11 ms)

  ● times

    expect(received).toBe(expected) // Object.is equality

    Expected: 10
    Received: 5

      11 |   const five = new Dollar(5);
      12 |   five.times(2)
    > 13 |   expect(five.amount).toBe(10);
         |                       ^
      14 | });
      15 |

      at Object.<anonymous> (src/__tests__/dollar.test.ts:13:23)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        4.039 s, estimated 6 s
```
  • Loading branch information
dodonki1223 committed Dec 7, 2021
1 parent 33bbf98 commit c35c4c3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/dollar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class Dollar {
public amount: number

constructor(amount: number) {
this.amount = amount
}

times(multiplier: number) {
}
}

0 comments on commit c35c4c3

Please sign in to comment.