Comments (3)
Just wanted to swing by to say thanks for the note, Timo! โค
I added a README notice in JamesMGreene/qunit-assert-close@e0300ba and archived the repo. ๐ ๐งน
from qunit.
I support including this, and there's even a use case in jQuery for asserting that early progress of an element animation approximates the pre-animation state (rather than e.g. introducing a discontinuity based on unit mismatch) at https://github.com/jquery/jquery/blob/99151d7ab0923aa3aeeb1b957a9063e4e20d31ae/test/unit/effects.js#L1830-L1832 .
from qunit.
Peer review of implementations:
-
qunit-assert-close:
Boils down toMath.abs(actual - expected) <= delta
https://github.com/JamesMGreene/qunit-assert-close/blob/v2.1.2/qunit-assert-close.js -
Chai:
Idem,Math.abs(actual - expected) <= delta
https://github.com/chaijs/chai/blob/v5.1.1/lib/chai/core/assertions.js#L3010 -
Deno
Similar, albeit swapped, reducing toMath.abs(expected - actual) <= tolerance
https://github.com/denoland/deno_std/blob/0.224.0/assert/assert_almost_equals.ts#L21 -
Expect.js
Different approach as "within(min, max)"
usingresult = actual >= min && actual <= max
https://github.com/Automattic/expect.js/blob/0.3.1/index.js#L246 -
Jasmine (and therefore Jest)
Different approach as "toBeCloseTo(,,precision=2)" where precision is the number of digits, not the delta. The main logic here is:const pow = Math.pow(10, precision + 1); const delta = Math.abs(expected - actual); const maxDelta = Math.pow(10, -precision) / 2; result = Math.round(delta * pow) <= maxDelta * pow
https://github.com/jasmine/jasmine/blob/v5.1.2/src/core/matchers/toBeCloseTo.js#L38
I'm going to go with @JamesMGreene 's qunit-assert-close for the most part, with an added type check in case the delta
argumet is missing, to catch otherwise-subtle mistakes.
from qunit.
Related Issues (20)
- Improve assert.async Function to Handle Type Checking
- Qunit v2 has incorrectly configured exports HOT 4
- Drop support for IE9-IE10 HOT 3
- Can we move this repo to a monorepo so we can more accurately test different usage scenarios? HOT 1
- Drop support for node < 18? HOT 1
- Can we drop builtin AMD support? HOT 6
- Can we start a `next` branch so I can start PRing improvements? HOT 1
- Let simple array data in test.each() serve as automatic labels
- [Feature Request]: Allow more customization of how errors are handled (especially uncaughtrejection). HOT 1
- Web Test Runner and QUnit reporting problems HOT 9
- qunit cannot parse private functions and properties HOT 2
- Support multiple `module` parameters (QUnit.config.module array) HOT 2
- Unify qunitjs.com and api.qunitjs.com
- [QUESTION] How can I forcefully abort a testcase and advance to next in queue HOT 1
- Let the test.each callback access the current case key HOT 3
- deepEqual should not compare constructors HOT 2
- Document QUnit.urlsParams
- Add tests for QUnit.config.fixture
- Stack trace cleaning preserves URLs with ports
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 qunit.