Skip to content

Commit

Permalink
🐛 【第2章 明白な実装】Dollar の副作用の確認
Browse files Browse the repository at this point in the history
最初の times 呼び出しで、5ドルはもう5ドルではなく10ドルになってしまうため、再度 times メソッドを呼ぶと 10 * 3 になってしまい、結果として 30ドルになってしまう
  • Loading branch information
dodonki1223 committed Dec 7, 2021
1 parent e321a47 commit 2a65e86
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/__tests__/dollar.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { Dollar } from '../dollar';

test('times', () => {
/*
「$5 * 2 = $10」のテスト
現状では以下の問題点あり
・フィールドは public
・コードには副作用がある
・金額なのに int型を使っている
*/
const five = new Dollar(5);
five.times(2)
expect(five.amount).toBe(10);
five.times(3)
expect(five.amount).toBe(15);
});

0 comments on commit 2a65e86

Please sign in to comment.