diff options
author | jboyson1 <jboyson@gitlab.com> | 2019-05-30 21:48:40 -0500 |
---|---|---|
committer | jboyson1 <jboyson@gitlab.com> | 2019-05-30 21:48:40 -0500 |
commit | fa89a6089e6a339d5cfdf6898d38e337a7a56515 (patch) | |
tree | 704dda9636edca9b62e8911ad6478d64a706468d | |
parent | 8ab0db4e8f74457c419e913dc6af6296a0a9fa52 (diff) | |
download | gitlab-ce-fa89a6089e6a339d5cfdf6898d38e337a7a56515.tar.gz |
Fix broken floating point tests61910-common_utils_spec-js-fails-locally-on-master-for-roundofffloat
Update tests to use toBeCloseTo instead of toBe for
floating point checks.
More info here:
https://jestjs.io/docs/en/expect#tobeclosetonumber-numdigits
-rw-r--r-- | spec/javascripts/lib/utils/common_utils_spec.js | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js index 0cd077a6099..296ee85089f 100644 --- a/spec/javascripts/lib/utils/common_utils_spec.js +++ b/spec/javascripts/lib/utils/common_utils_spec.js @@ -852,20 +852,20 @@ describe('common_utils', () => { describe('roundOffFloat', () => { it('Rounds off decimal places of a float number with provided precision', () => { - expect(commonUtils.roundOffFloat(3.141592, 3)).toBe(3.142); + expect(commonUtils.roundOffFloat(3.141592, 3)).toBeCloseTo(3.142); }); it('Rounds off a float number to a whole number when provided precision is zero', () => { - expect(commonUtils.roundOffFloat(3.141592, 0)).toBe(3); - expect(commonUtils.roundOffFloat(3.5, 0)).toBe(4); + expect(commonUtils.roundOffFloat(3.141592, 0)).toBeCloseTo(3); + expect(commonUtils.roundOffFloat(3.5, 0)).toBeCloseTo(4); }); it('Rounds off float number to nearest 0, 10, 100, 1000 and so on when provided precision is below 0', () => { - expect(commonUtils.roundOffFloat(34567.14159, -1)).toBe(34570); - expect(commonUtils.roundOffFloat(34567.14159, -2)).toBe(34600); - expect(commonUtils.roundOffFloat(34567.14159, -3)).toBe(35000); - expect(commonUtils.roundOffFloat(34567.14159, -4)).toBe(30000); - expect(commonUtils.roundOffFloat(34567.14159, -5)).toBe(0); + expect(commonUtils.roundOffFloat(34567.14159, -1)).toBeCloseTo(34570); + expect(commonUtils.roundOffFloat(34567.14159, -2)).toBeCloseTo(34600); + expect(commonUtils.roundOffFloat(34567.14159, -3)).toBeCloseTo(35000); + expect(commonUtils.roundOffFloat(34567.14159, -4)).toBeCloseTo(30000); + expect(commonUtils.roundOffFloat(34567.14159, -5)).toBeCloseTo(0); }); }); |