Comments (8)
I will push update for this shortly, thank you so much for reporting this
from eslint-plugin-vitest.
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.
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);
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.
Hope the latest release fixes this issue
from eslint-plugin-vitest.
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.
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.
No, the initial problem was solved, thanks for being so reactive.
from eslint-plugin-vitest.
awesome, I'll still consider your new rule proposal. I'm glad my quick fix was helpful.
from eslint-plugin-vitest.
Related Issues (20)
- `expect-expect` - doesn't make much sense for skipped tests HOT 3
- expect-expect doesn't factor in assert HOT 3
- Add rule `prefer-repeats` HOT 1
- `vitest/no-conditional-tests` false positive HOT 1
- some rules missing in readme HOT 2
- vitest/expect-expect shouldn't require assertions for bench HOT 1
- Feature request: `consistent-test-file-path` HOT 2
- Feature request: formatting rules HOT 1
- Invalid flat config HOT 2
- `bench` throw error `Prefer using it instead of test within describe`
- `expect-expect` fails even if `expectTypeOf` is present HOT 7
- Add require `describe`, `it` and `vi` import HOT 1
- Extend the `no-identical-title` rule to support `suite` test block pattern HOT 4
- Consider rule for naming mocks created with `vi.fn()` HOT 1
- Results of weekly scheduled smoke test HOT 1
- Throwing with ESLint 9 and flat config HOT 1
- [BUG] Converting circular structure to JSON HOT 5
- Please provide non-flat config HOT 6
- Declaration file missing plugin configs
- Results of weekly scheduled smoke test HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-vitest.