{"id":15365928,"url":"https://github.com/andywer/deep-assert","last_synced_at":"2025-08-28T19:21:31.212Z","repository":{"id":45052138,"uuid":"183773770","full_name":"andywer/deep-assert","owner":"andywer","description":"🔍 Better deep-equals comparison, supporting custom property assertions and pretty diffs.","archived":false,"fork":false,"pushed_at":"2022-01-12T10:47:49.000Z","size":194,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T21:07:58.639Z","etag":null,"topics":["assertions","deep-equals","diff","javascript","json","json-diff","nodejs","testing","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/andywer.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}},"created_at":"2019-04-27T13:03:30.000Z","updated_at":"2022-01-12T10:03:23.000Z","dependencies_parsed_at":"2022-09-02T23:23:22.909Z","dependency_job_id":null,"html_url":"https://github.com/andywer/deep-assert","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Fdeep-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Fdeep-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Fdeep-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andywer%2Fdeep-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andywer","download_url":"https://codeload.github.com/andywer/deep-assert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249057616,"owners_count":21205904,"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":["assertions","deep-equals","diff","javascript","json","json-diff","nodejs","testing","typescript"],"created_at":"2024-10-01T13:16:43.651Z","updated_at":"2025-04-15T10:51:23.347Z","avatar_url":"https://github.com/andywer.png","language":"TypeScript","readme":"# deep-assert\n[![Build Status](https://img.shields.io/travis/andywer/deep-assert/master.svg?style=flat-square)](https://travis-ci.org/andywer/deep-assert)\n[![npm](https://img.shields.io/npm/v/deep-assert.svg?style=flat-square)](https://www.npmjs.com/package/deep-assert)\n\nThe most developer-friendly way to write assertions for large or complicated objects and arrays.\n\n* Use `any()` and `satisfies()` property matchers\n* Short, but precise diffs, even for large nested objects\n* Works with objects, arrays, dates, buffers, and more\n* Write custom property assertions\n* Zero dependencies\n\n\u003cbr /\u003e\n\n\u003cp align=center\u003e\n  \u003cimg alt=\"Terminal\" src=\"./media/terminal.png\" width=\"80%\" /\u003e\n\u003c/p\u003e\n\n## Installation\n\n```\nnpm install deep-assert\n```\n\n## Usage\n\n### Basic\n\nLet's say we want to check if an array of user objects matches our expectation, but we don't know what the `id` is gonna be, since it's a random ID. It's easy, using `any()`.\n\n```js\nimport * as assert from \"assert-deep\"\n\nassert.deepEquals(\n  // Actual value:\n  {\n    id: Math.random(),\n    name: \"John Smith\",\n    meta: {\n      isActive: true,\n      lastLogin: new Date(\"2019-04-29T12:31:00\")\n    }\n  },\n  // Expectation:\n  {\n    id: assert.any(),\n    name: \"John Smith\",\n    meta: {\n      isActive: true,\n      lastLogin: new Date(\"2019-04-29T12:31:00\")\n    }\n  }\n])\n```\n\n### Custom assertions\n\nLet's try the previous use case again, but this time we check that the `id` is a valid UUIDv4. We use the `satisfies()` helper function to create a custom assertion to be used within the object expectation.\n\n```js\nimport * as assert from \"assert-deep\"\n\nconst assertPositiveNumber = () =\u003e assert.satisfies(value =\u003e typeof value === \"number\" \u0026\u0026 value \u003e 0)\n\nassert.deepEquals(\n  // Actual value:\n  {\n    id: Math.random(),\n    name: \"John Smith\",\n    meta: {\n      isActive: true,\n      lastLogin: new Date(\"2019-04-29T12:31:00\")\n    }\n  },\n  // Expectation:\n  {\n    id: assertPositiveNumber(),\n    name: \"John Smith\",\n    meta: {\n      isActive: true,\n      lastLogin: new Date(\"2019-04-29T12:31:00\")\n    }\n  }\n])\n```\n\n### Spreading any()\n\nNormally `deepEquals()` will fail if there are properties on the tested object that don't exist on the expectation. We can use `any()` with the object spread operator to allow additional properties to be present.\n\n`deepEquals()` will then only check the expected properties and ignore all other ones.\n\n```js\nimport * as assert from \"assert-deep\"\n\nassert.deepEquals(\n  // Actual value:\n  {\n    id: Math.random(),\n    name: \"John Smith\",\n    meta: {\n      isActive: true,\n      lastLogin: new Date(\"2019-04-29T12:31:00\")\n    }\n  },\n  // Expectation:\n  {\n    id: assert.any(),\n    name: \"John Smith\",\n    ...assert.any()\n  }\n])\n```\n\n### Recursive objects\n\nYou can call `deepEquals()` in a custom `satisfies()` as well. This way you can easily test recursive data structures, for instance.\n\n```js\nimport * as assert from \"assert-deep\"\n\nconst actual = { foo: {} }\nactual.foo.parent = actual.foo\n\nassert.deepEquals(actual, {\n  foo: assert.satisfies(foo =\u003e assert.deepEquals(foo, { parent: foo }))\n})\n```\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandywer%2Fdeep-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandywer%2Fdeep-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandywer%2Fdeep-assert/lists"}