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

Jest compatibility API: expect.closeTo() is not supported #2809

Closed
4 tasks done
trivikr opened this issue Feb 5, 2023 · 0 comments · Fixed by #4260
Closed
4 tasks done

Jest compatibility API: expect.closeTo() is not supported #2809

trivikr opened this issue Feb 5, 2023 · 0 comments · Fixed by #4260
Labels
enhancement New feature or request

Comments

@trivikr
Copy link
Contributor

trivikr commented Feb 5, 2023

Clear and concise description of the problem

The expect.closeTo() API is not supported.

From Jest docs:

expect.closeTo(number, numDigits?) is useful when comparing floating point numbers in object properties or array item.

import { expect, test } from "vitest";

test('compare float in object properties', () => {
  expect({
    title: '0.1 + 0.2',
    sum: 0.1 + 0.2,
  }).toEqual({
    title: '0.1 + 0.2',
    sum: expect.closeTo(0.3, 5),
  });
});
 FAIL  example.spec.js > compare float in object properties
TypeError: expect.closeTo is not a function
 ❯ example.spec.js:9:17
      7|   }).toEqual({
      8|     title: '0.1 + 0.2',
      9|     sum: expect.closeTo(0.3, 5),
       |                 ^
     10|   });
     11| });

Suggested solution

Support expect.closeTo() API.

Alternative

Skip expect.closeTo() API, and direct users to run toBeCloseTo on object property or array item.

Additional context

No response

Validations

@sheremet-va sheremet-va added the enhancement New feature or request label Feb 5, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants