neherlab / covid19_scenarios

Models of COVID-19 outbreak trajectories and hospital demand
https://covid19-scenarios.org
MIT License
1.36k stars 354 forks source link

Introduce custom Jest snapshot matchers #281

Closed ivan-aksamentov closed 4 years ago

ivan-aksamentov commented 4 years ago

🙋 Feature Request

Introduce a set of custom Jest snapshot matchers that could work for our assertions better. https://jestjs.io/docs/en/expect#custom-snapshot-matchers https://github.com/maasencioh/jest-matcher-deep-close-to

We use a lot of floating point numbers and they are not correctly compared by default matchers.

It is preferred to not go too deep into the app-specific data structures ant to not hard-code object layouts etc., if possible.

It is desirable to parameterize the "closeness" of the compared values, either on absolute difference (commonly called "epsilon") or on Units in the Last Place (ULPs) in its IEEE-754 representation.

🔦 Context

We want to avoud hardcoding expectations and comparing them with .toBeClose()because it is very tedious to fix all the tests after every small change in the algorithm. We want to update snapshots with jest -u instead. However, this require a snapshot matcher that understands floating point numbers.

😯 Describe the feature

💻 Examples

💁 Possible Solution

Related

ivan-aksamentov commented 4 years ago

@abrie Could you please let me know if #327 is still useful? Could we revive and rebase it?

ivan-aksamentov commented 4 years ago

Fixed in #327