Testing · Junior · Question 18 of 78
Why does this check fail and how do you fix it?
expect(0.1 + 0.2).toBe(0.3);- ✓Correct answer: Floating-point arithmetic gives 0.30000000000000004; use
toBeCloseTo(0.3) - 2
toBedoesn't work with numbers; usetoEqual - 3It doesn't fail
Explanation
toBeCloseTo compares with a given precision (2 decimal digits by default).