Skip to content

expect(...).to.be.closeTo(expected, delta) #156

Description

@missingdays

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

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

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions