Giter Site home page Giter Site logo

Comments (8)

veritem avatar veritem commented on August 20, 2024 1

I will push update for this shortly, thank you so much for reporting this

from eslint-plugin-vitest.

veritem avatar veritem commented on August 20, 2024

uuhmm, intresting, I haven't personally dealt with floating points, so do you have a repro I can base on fixing this rule?

from eslint-plugin-vitest.

anisometropie avatar anisometropie commented on August 20, 2024

here are a few simple examples you can use :

expect({ a: 1, b: 2, ...{ c: 3} }).toEqual({ a: 1, b: 2, c: 3});
expect('abcd' + 'efgh').toEqual('abcdefgh');
expect(1 + 2).toEqual(3);
expect(0.1 + 0.2).toEqual(0.3);

Screenshot_20230228_111851

with the rule enabled, as you can see the first line is okay, toEqual is the right function to compare objects.
on the second line the rule wants me to change toEqual and use toBe instead, which is fine
on the third line, for integer the rule wants me to use toBe also, this is fine to too.

—> but on the fourth line, the rule wants me to use toBe for floating point, which is incorrect.

from eslint-plugin-vitest.

veritem avatar veritem commented on August 20, 2024

Hope the latest release fixes this issue

from eslint-plugin-vitest.

anisometropie avatar anisometropie commented on August 20, 2024

Thank you for your responsiveness in solving our issue :)

Now, having come to think a bit more about this, perhaps you could have another rule that follows the doc recommendation.

Both jest doc and vitest doc recommend not to use toBe with floating point numbers and to use toBeCloseTo instead.

Do you think having a rule for that would be helpful ?

PS: Pushing these reflections further .

we know that

  • For scalar values like numbers and strings it’s better to use toBe
  • it’s not recommended to use toBe for floating point numbers

I imagine having a rule that recommends using toBeCloseTo for floating point instead of toEqual could help.

The same problem arises for toEqual and toBe. These 2 tests fail because of the nature of floating points :

expect(0.1 + 0.2).toEqual(0.3);
expect(0.1 + 0.2).toBe(0.3);

But the only thing is that the doc doesn’t say anything about not using toEqual for floating points, So I’m really more sceptical about this part.

from eslint-plugin-vitest.

veritem avatar veritem commented on August 20, 2024

I get, i'll have to think abit more on additing a different rule. But does it still yell at you even on floating points?

from eslint-plugin-vitest.

anisometropie avatar anisometropie commented on August 20, 2024

No, the initial problem was solved, thanks for being so reactive.

from eslint-plugin-vitest.

veritem avatar veritem commented on August 20, 2024

awesome, I'll still consider your new rule proposal. I'm glad my quick fix was helpful.

from eslint-plugin-vitest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.