Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/asserts/big-number-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ module.exports = function bigNumberAssert({ validateSignificantDigits = true } =
throw new Error('BigNumber is not installed');
}

BigNumber.DEBUG = !!validateSignificantDigits;

/**
* Class name.
*/
Expand All @@ -39,7 +37,11 @@ module.exports = function bigNumberAssert({ validateSignificantDigits = true } =
*/

this.validate = value => {
const bigNumberDebug = BigNumber.DEBUG;

try {
BigNumber.DEBUG = !!validateSignificantDigits;

const number = new BigNumber(value);

if (Number.isNaN(number.toNumber())) {
Expand All @@ -51,6 +53,8 @@ module.exports = function bigNumberAssert({ validateSignificantDigits = true } =
}

throw new Violation(this, value);
} finally {
BigNumber.DEBUG = bigNumberDebug;
}

return true;
Expand Down
8 changes: 6 additions & 2 deletions src/asserts/big-number-equal-to-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = function bigNumberEqualToAssert(value, { validateSignificantDig
throw new Error('BigNumber is not installed');
}

BigNumber.DEBUG = !!validateSignificantDigits;

/**
* Extend `Assert` with `BigNumberAssert`.
*/
Expand All @@ -55,7 +53,11 @@ module.exports = function bigNumberEqualToAssert(value, { validateSignificantDig
*/

this.validate = value => {
const bigNumberDebug = BigNumber.DEBUG;

try {
BigNumber.DEBUG = !!validateSignificantDigits;

Assert.bigNumber({ validateSignificantDigits }).validate(value);

const number = new BigNumber(value);
Expand All @@ -72,6 +74,8 @@ module.exports = function bigNumberEqualToAssert(value, { validateSignificantDig
}

throw new Violation(this, value, context);
} finally {
BigNumber.DEBUG = bigNumberDebug;
}

return true;
Expand Down
8 changes: 6 additions & 2 deletions src/asserts/big-number-greater-than-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = function bigNumberGreaterThanAssert(threshold, { validateSignif
throw new Error('BigNumber is not installed');
}

BigNumber.DEBUG = !!validateSignificantDigits;

/**
* Extend `Assert` with `BigNumberAssert`.
*/
Expand All @@ -55,7 +53,11 @@ module.exports = function bigNumberGreaterThanAssert(threshold, { validateSignif
*/

this.validate = value => {
const bigNumberDebug = BigNumber.DEBUG;

try {
BigNumber.DEBUG = !!validateSignificantDigits;

Assert.bigNumber({ validateSignificantDigits }).validate(value);

const number = new BigNumber(value);
Expand All @@ -72,6 +74,8 @@ module.exports = function bigNumberGreaterThanAssert(threshold, { validateSignif
}

throw new Violation(this, value, context);
} finally {
BigNumber.DEBUG = bigNumberDebug;
}

return true;
Expand Down
8 changes: 6 additions & 2 deletions src/asserts/big-number-greater-than-or-equal-to-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = function bigNumberGreaterThanOrEqualToAssert(threshold, { valid
throw new Error('BigNumber is not installed');
}

BigNumber.DEBUG = !!validateSignificantDigits;

/**
* Extend `Assert` with `BigNumberAssert`.
*/
Expand All @@ -54,7 +52,11 @@ module.exports = function bigNumberGreaterThanOrEqualToAssert(threshold, { valid
*/

this.validate = value => {
const bigNumberDebug = BigNumber.DEBUG;

try {
BigNumber.DEBUG = !!validateSignificantDigits;

Assert.bigNumber({ validateSignificantDigits }).validate(value);

const number = new BigNumber(value);
Expand All @@ -71,6 +73,8 @@ module.exports = function bigNumberGreaterThanOrEqualToAssert(threshold, { valid
}

throw new Violation(this, value, context);
} finally {
BigNumber.DEBUG = bigNumberDebug;
}

return true;
Expand Down
8 changes: 6 additions & 2 deletions src/asserts/big-number-less-than-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = function bigNumberLessThan(threshold, { validateSignificantDigi
throw new Error('BigNumber is not installed');
}

BigNumber.DEBUG = !!validateSignificantDigits;

/**
* Extend `Assert` with `BigNumberAssert`.
*/
Expand All @@ -55,7 +53,11 @@ module.exports = function bigNumberLessThan(threshold, { validateSignificantDigi
*/

this.validate = value => {
const bigNumberDebug = BigNumber.DEBUG;

try {
BigNumber.DEBUG = !!validateSignificantDigits;

Assert.bigNumber({ validateSignificantDigits }).validate(value);

const number = new BigNumber(value);
Expand All @@ -72,6 +74,8 @@ module.exports = function bigNumberLessThan(threshold, { validateSignificantDigi
}

throw new Violation(this, value, context);
} finally {
BigNumber.DEBUG = bigNumberDebug;
}

return true;
Expand Down
8 changes: 6 additions & 2 deletions src/asserts/big-number-less-than-or-equal-to-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = function bigNumberLessThanOrEqualToAssert(threshold, { validate
throw new Error('BigNumber is not installed');
}

BigNumber.DEBUG = !!validateSignificantDigits;

/**
* Extend `Assert` with `BigNumberAssert`.
*/
Expand All @@ -55,7 +53,11 @@ module.exports = function bigNumberLessThanOrEqualToAssert(threshold, { validate
*/

this.validate = value => {
const bigNumberDebug = BigNumber.DEBUG;

try {
BigNumber.DEBUG = !!validateSignificantDigits;

Assert.bigNumber({ validateSignificantDigits }).validate(value);

const number = new BigNumber(value);
Expand All @@ -72,6 +74,8 @@ module.exports = function bigNumberLessThanOrEqualToAssert(threshold, { validate
}

throw new Violation(this, value, context);
} finally {
BigNumber.DEBUG = bigNumberDebug;
}

return true;
Expand Down