Automattic / Automattic/expect.js
expect(...).to.be.closeTo(expected, delta)
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 207
- PR merge metrics
- No merged PRs in 30d
Description
chai.js has cool API that allows for checking if two values (including floats) are close to each other.
For example, you can't realy check
``` javascript
expect(0.1+0.2).to.be(0.3)
```
because there is always rounding error in floating point calculation.
So instead in chai you write
``` javascript
let EPS = 1e-5;
expect(0.1+0.2).to.be.closeTo(0.3, EPS)
```
This function is oneliner, so this totaly fits "minimalistic" idea.
I know that I can use something like
``` javascript
expect(abs(f1-f2)).to.be.below(EPS)
```
but this is not very intuitive for reader that my intention is just check that **f1** and **f2** are just close to each other.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the existing expect(...).to.be assertion API in the repository and identify where chained assertion methods are defined. Implement the requested closeTo(expected, delta) behavior for comparing numeric values, then verify that the example distinguishes floating-point rounding from exact equality.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100