Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow toBeCloseTo to accept an array #4116

Closed
Scimonster opened this issue Jul 25, 2017 · 5 comments
Closed

Allow toBeCloseTo to accept an array #4116

Scimonster opened this issue Jul 25, 2017 · 5 comments

Comments

@Scimonster
Copy link

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
The toBeCloseTo() matcher accepts only scalar numbers. Passing an array automatically fails the test.

What is the expected behavior?
For it to work when passing an array, to check that all items of received are close to expected.

Example:

expect([0, 1, 2]).toBeCloseTo([0.0001, 0.9999, 2]);

I think this is different from #3654 and #4057 in that it's simply extending this existing matcher in an intuitive manner, and isn't limited to extremely specific use cases.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

Jest 20.0.4 with essentially the default Create React App configuration.

@cpojer
Copy link
Member

cpojer commented Jul 25, 2017

I don't think there is any benefit over calling the matcher individually on each item. If that's not sufficient, there is expect.extend to build your own matchers.

@cpojer cpojer closed this as completed Jul 25, 2017
@clawconduce
Copy link

See #4058

@garyo
Copy link

garyo commented Oct 20, 2020

I know this is closed, and I'll write my own, but it would be really nice if .toBeCloseTo would just accept arrays.

@logi
Copy link

logi commented Nov 27, 2020

For anyone coming in via a search, there is now https://www.npmjs.com/package/jest-matcher-deep-close-to

@cpojer the download count on that project disagrees

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants