{"id":19063426,"url":"https://github.com/nmuldavin/chai-almost","last_synced_at":"2025-04-26T18:12:18.470Z","repository":{"id":57196515,"uuid":"91139342","full_name":"nmuldavin/chai-almost","owner":"nmuldavin","description":"Extends Chai with assertions that allow for floating point rounding errors","archived":false,"fork":false,"pushed_at":"2019-03-17T04:57:29.000Z","size":41,"stargazers_count":4,"open_issues_count":3,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-14T10:04:46.875Z","etag":null,"topics":["approximation","assertion-library","assertions","chai","chai-assertions","chai-plugin","deep-equals","javascript","mocha","rounding-error","testing","testing-tools"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nmuldavin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-13T00:39:29.000Z","updated_at":"2021-05-12T02:57:08.000Z","dependencies_parsed_at":"2022-09-15T07:20:32.593Z","dependency_job_id":null,"html_url":"https://github.com/nmuldavin/chai-almost","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmuldavin%2Fchai-almost","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmuldavin%2Fchai-almost/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmuldavin%2Fchai-almost/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nmuldavin%2Fchai-almost/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nmuldavin","download_url":"https://codeload.github.com/nmuldavin/chai-almost/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250847355,"owners_count":21497181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["approximation","assertion-library","assertions","chai","chai-assertions","chai-plugin","deep-equals","javascript","mocha","rounding-error","testing","testing-tools"],"created_at":"2024-11-09T00:35:53.814Z","updated_at":"2025-04-25T15:44:06.191Z","avatar_url":"https://github.com/nmuldavin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chai-almost\n\n[![travis](https://travis-ci.org/nmuldavin/chai-almost.svg?branch=master)](https://travis-ci.org/nmuldavin/chai-almost)\n[![npm](https://img.shields.io/npm/v/chai-almost.svg)](https://www.npmjs.com/package/chai-almost)\n[![node](https://img.shields.io/badge/node-%3E=0.10-green.svg)](https://www.npmjs.com/package/chai-almost)\n\nExtends [chai](https://github.com/chaijs/chai) with assertions that allow numbers to be \"almost\" equal (as in, within some tolerance of one another). This is useful in particular when accounting for floating point rounding errors or other approximations.\n\n## Installation\n\n```\nnpm install chai-almost --save-dev\n```\n\n## Use\nTo use, import the module then invoke it with `chai.use`:\n\n```\nconst chai = require('chai');\nconst chaiAlmost = require('chai-almost');\n\nchai.use(chaiAlmost());\n```\n\nBy default, `chai-almost` allows a tolerance of 1 x 10\u003csup\u003e-6\u003c/sup\u003e. This will let most rounding errors pass safely but will still reject most true inequalities. You may override this value by passing your desired tolerance as an argument to the module on invocation:\n\n```\nchai.use(chaiAlmost(0.1));\n```\n\n### Assertions\n\nThe `almost` assertion may be used chainably with deep or shallow equality:\n\n```\n// shallow\nexpect(3.9999999).to.almost.equal(4);\t        // passes\nexpect(3.9).to.almost.equal(4);\t\t\t// fails\nexpect(4.0000001).to.be.almost(4);\t\t// passes\nexpect(4.1).to.not.be.almost(4);\t\t// passes\n\n// deep\nexpect({ taco: 'pastor', num: 3.9999999 }).to.almost.eql({ taco: 'pastor', num: 4 }); // passes\nexpect([[1, 2, 2.9999999], 1.0000001]).to.be.deep.almost([[1, 2, 3], 1]);             // passes\nexpect({ taco: 'pastor', num: 3.9 }).to.not.almost.eql({ taco: 'pastor', num: 4 });   // passes\n```\n\nEquality checks on non-numbers are left unchanged:\n\n```\nexpect('taco').to.almost.equal('taco');   // still passes\nexpect({ x: 5 }).to.be.almost({ x: 5 });  // still fails (shallow equality)\nexpect(['tacos', 2, 3]).to.be.deep.almost(['burritos', 2, 2.9999999]); // still fails\n```\n\n### Specific tolerance\n\nA single-instance custom tolerance for shallow or deep equality may be passed in as the second argument to `almost`:\n\n```\nexpect(10).to.be.almost(15, 10)                   // passes\nexpect([4, 2, 5]).to.be.deep.almost([3, 4, 7], 3) // passes\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmuldavin%2Fchai-almost","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnmuldavin%2Fchai-almost","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnmuldavin%2Fchai-almost/lists"}