Skip to content

Commit

Permalink
Added sinon to test console.warn
Browse files Browse the repository at this point in the history
  • Loading branch information
dvd101x committed May 12, 2024
1 parent b164642 commit 8ac2548
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 0 deletions.
225 changes: 225 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"fraction.js": "4.3.4",
"javascript-natural-sort": "^0.7.1",
"seedrandom": "^3.0.5",
"sinon": "^17.0.1",
"tiny-emitter": "^2.1.0",
"typed-function": "^4.1.1"
},
Expand Down
14 changes: 14 additions & 0 deletions test/unit-tests/core/config.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'assert'
import math from '../../../src/defaultInstance.js'
import sinon from 'sinon'

describe('config', function () {
it('should allow setting config after having overwritten import', function () {
Expand All @@ -20,7 +21,20 @@ describe('config', function () {

it('should work with config epsilon during depercation', function () {
const math2 = math.create()
// Add a spy to temporary disable console.warn
const warnStub = sinon.stub(console, 'warn')

// Set epsilon to throw a warning and set relTol and absTol
assert.doesNotThrow(function () { math2.config({ epsilon: 1e-5 }) })

// Check if epsilon is set as relTol and absTol
assert.strictEqual(math2.config().relTol, 1e-5)
assert.strictEqual(math2.config().absTol, 1e-8)

// Check if console.warn was called
assert.strictEqual(warnStub.callCount, 1)

// Restore console.warn
warnStub.restore()
})
})
3 changes: 3 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4300,6 +4300,9 @@ export interface Help {
export interface ConfigOptions {
relTol?: number
absTol?: number
/**
* @deprecated Use `relTol` and `absTol` instead
*/
epsilon?: number
matrix?: 'Matrix' | 'Array'
number?: 'number' | 'BigNumber' | 'Fraction'
Expand Down

0 comments on commit 8ac2548

Please sign in to comment.