diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index 81d74a35..e87789b0 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -3027,10 +3027,10 @@ function closeTo(expected, delta, msg) { new Assertion(obj, flagMsg, ssfi, true).is.numeric; let message = 'A `delta` value is required for `closeTo`'; - if (!delta) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi); + if (delta == undefined) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi); new Assertion(delta, flagMsg, ssfi, true).is.numeric; message = 'A `expected` value is required for `closeTo`'; - if (!delta) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi); + if (expected == undefined) throw new AssertionError(flagMsg ? `${flagMsg}: ${message}` : message, undefined, ssfi); new Assertion(expected, flagMsg, ssfi, true).is.numeric; const abs = (x) => x < 0n ? -x : x; diff --git a/test/assert.js b/test/assert.js index c1c528cb..89395b05 100644 --- a/test/assert.js +++ b/test/assert.js @@ -1893,6 +1893,7 @@ describe('assert', function () { assert.closeTo(1.5, 1.0, 0.5); assert.closeTo(10, 20, 20); assert.closeTo(-10, 20, 30); + assert.closeTo(10, 10, 0); err(function(){ assert.closeTo(2, 1.0, 0.5, 'blah');