{"id":14989732,"url":"https://github.com/mesaugat/chai-exclude","last_synced_at":"2025-04-13T11:48:22.892Z","repository":{"id":26264683,"uuid":"107700261","full_name":"mesaugat/chai-exclude","owner":"mesaugat","description":"Exclude keys to compare from a deep equal operation with chai expect or assert.","archived":false,"fork":false,"pushed_at":"2024-11-20T14:03:55.000Z","size":778,"stargazers_count":32,"open_issues_count":2,"forks_count":12,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T07:06:20.374Z","etag":null,"topics":["assert","bdd","chai","chai-exclude","chai-plugin","exclude","expect","mocha","tdd","unit-testing"],"latest_commit_sha":null,"homepage":"https://yarn.pm/chai-exclude","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mesaugat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-20T16:19:48.000Z","updated_at":"2025-02-22T23:43:44.000Z","dependencies_parsed_at":"2022-08-07T12:00:10.965Z","dependency_job_id":"b08b8d9d-344d-44ad-a15f-b17ecf7fb627","html_url":"https://github.com/mesaugat/chai-exclude","commit_stats":{"total_commits":163,"total_committers":16,"mean_commits":10.1875,"dds":"0.26993865030674846","last_synced_commit":"e2f3c4b75fae026ad30bd20754b96bba0769d7f7"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesaugat%2Fchai-exclude","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesaugat%2Fchai-exclude/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesaugat%2Fchai-exclude/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mesaugat%2Fchai-exclude/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mesaugat","download_url":"https://codeload.github.com/mesaugat/chai-exclude/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710411,"owners_count":21149186,"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":["assert","bdd","chai","chai-exclude","chai-plugin","exclude","expect","mocha","tdd","unit-testing"],"created_at":"2024-09-24T14:18:50.518Z","updated_at":"2025-04-13T11:48:22.869Z","avatar_url":"https://github.com/mesaugat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chai-exclude\n\n[![npm](https://img.shields.io/npm/v/chai-exclude.svg)](https://www.npmjs.com/package/chai-exclude)\n[![npm](https://img.shields.io/npm/dw/chai-exclude.svg)](https://www.npmjs.com/package/chai-exclude)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n[![CI Status](https://github.com/mesaugat/chai-exclude/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/mesaugat/chai-exclude/actions/workflows/test.yml)\n\nExclude keys to compare from a deep equal operation with chai [expect](http://chaijs.com/api/bdd/) or [assert](http://chaijs.com/api/assert/).\n\n## Why?\n\nSometimes you'll need to exclude object properties that generate unique values while doing an assertion. This plugin makes it easier to remove those properties from comparison.\n\nWorks with both objects and array of objects with or without circular references.\n\n## Installation\n\n`chai-exclude` is an ESM package targeting Chai v5 and above.\n\n```bash\nnpm install chai-exclude --save-dev\n```\n\nIf you are using Chai v4, you can use the CommonJS version of the package.\n\n```bash\nnpm install chai-exclude@2.1.1 --save-dev\n```\n\n## Usage\n\n```js\nimport { use } from 'chai'\nimport chaiExclude from 'chai-exclude'\n\n// If you are using TypeScript, the typings for chai-exclude are included in the package\nuse(chaiExclude)\n```\n\n## Examples\n\nAll these examples are for JavaScript. If you are using TypeScript and `assert`, you'll need to deal with strict types. Take a look at the [type definition](index.d.ts).\n\n### a) excluding\n\n1. Excluding a top level property from an object\n\n```js\n// Object\nassert.deepEqualExcluding({ a: 'a', b: 'b' }, { b: 'b' }, 'a')\nassert.deepEqualExcluding({ a: 'a', b: 'b' }, { a: 'z', b: 'b' }, 'a')\n\nexpect({ a: 'a', b: 'b' }).excluding('a').to.deep.equal({ b: 'b' })\nexpect({ a: 'a', b: 'b' }).excluding('a').to.deep.equal({ a: 'z', b: 'b' })\n\n// Array\nassert.deepEqualExcluding([{ a: 'a', b: 'b' }], [{ b: 'b' }], 'a')\nassert.deepEqualExcluding([{ a: 'a', b: 'b' }], [{ a: 'z', b: 'b' }], 'a')\n\nexpect([{ a: 'a', b: 'b' }]).excluding('a').to.deep.equal([{ b: 'b' }])\nexpect([{ a: 'a', b: 'b' }]).excluding('a').to.deep.equal([{ a: 'z', b: 'b' }])\n```\n\n2. Excluding multiple top level properties from an object\n\n```js\nconst obj = {\n  a: 'a',\n  b: 'b',\n  c: {\n    d: 'd',\n    e: 'e'\n  }\n}\n\n// Object\nassert.deepEqualExcluding(obj, { b: 'b' }, ['a', 'c'])\nassert.deepEqualExcluding(obj, { a: 'z', b: 'b' }, ['a', 'c'])\n\nexpect(obj).excluding(['a', 'c']).to.deep.equal({ b: 'b' })\nexpect(obj).excluding(['a', 'c']).to.deep.equal({ a: 'z', b: 'b' })\n\nconst array = [\n  {\n    a: 'a',\n    b: 'b',\n    c: {\n      d: 'd',\n      e: 'e'\n    }\n  }\n]\n\n// Array\nassert.deepEqualExcluding(array, [{ b: 'b' }], ['a', 'c'])\nassert.deepEqualExcluding(array, [{ a: 'z', b: 'b' }], ['a', 'c'])\n\nexpect(array).excluding(['a', 'c']).to.deep.equal([{ b: 'b' }])\nexpect(array).excluding(['a', 'c']).to.deep.equal([{ a: 'z', b: 'b' }])\n```\n\n### b) excludingEvery\n\n1. Excluding every property in a deeply nested object\n\n```js\nconst actualObj = {\n  a: 'a',\n  b: 'b',\n  c: {\n    a: 'a',\n    b: {\n      a: 'a',\n      d: {\n        a: 'a',\n        b: 'b',\n        d: null\n      }\n    }\n  },\n  d: ['a', 'c']\n}\n\nconst actualArray = [actualObj]\n\nconst expectedObj = {\n  a: 'z',     // a is excluded from comparison\n  b: 'b',\n  c: {\n    b: {\n      d: {\n        b: 'b',\n        d: null\n      }\n    }\n  },\n  d: ['a', 'c']\n}\n\nconst expectedArray = [expectedObj]\n\n// Object\nassert.deepEqualExcludingEvery(actualObj, expectedObj, 'a')\nexpect(actualObj).excludingEvery('a').to.deep.equal(expectedObj)\n\n// Array\nassert.deepEqualExcludingEvery(actualArray, expectedArray, 'a')\nexpect(actualArray).excludingEvery('a').to.deep.equal(expectedArray)\n```\n\n2. Excluding multiple properties in a deeply nested object\n\n```js\nconst actualObj = {\n  a: 'a',\n  b: 'b',\n  c: {\n    a: 'a',\n    b: {\n      a: 'a',\n      d: {\n        a: 'a',\n        b: 'b',\n        d: null\n      }\n    }\n  },\n  d: ['a', 'c']\n}\n\nconst actualArray = [actualObj]\n\nconst expectedObj = {\n  b: 'b',\n  c: {\n    b: {\n    }\n  }\n}\n\nconst expectedArray = [expectedObj]\n\n// Object\nassert.deepEqualExcludingEvery(actualObj, expectedObj, ['a', 'd'])\nexpect(actualObj).excludingEvery(['a', 'd']).to.deep.equal(expectedObj)\n\n// Array\nassert.deepEqualExcludingEvery(actualArray, expectedArray, ['a', 'd'])\nexpect(actualArray).excludingEvery(['a', 'd']).to.deep.equal(expectedArray)\n```\n\n## Contributing\n\nContributions are welcome. If you have any questions create an issue [here](https://github.com/mesaugat/chai-exclude/issues).\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesaugat%2Fchai-exclude","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmesaugat%2Fchai-exclude","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmesaugat%2Fchai-exclude/lists"}