deep-assert
Advanced tools
+1
-1
| import { Options } from "./deep-equals"; | ||
| export * from "./deep-equals"; | ||
| export default function deepEquals(actual: any, expected: any, opts?: Options): void; | ||
| export default function deepEquals(actual: any, expected: any, opts?: Options): boolean; | ||
| export { deepEquals }; |
+1
-0
@@ -14,4 +14,5 @@ "use strict"; | ||
| } | ||
| return true; | ||
| } | ||
| exports.default = deepEquals; | ||
| exports.deepEquals = deepEquals; |
+1
-1
| { | ||
| "name": "deep-assert", | ||
| "version": "0.1.0", | ||
| "version": "0.2.0", | ||
| "description": "Better deep-equals object expectations, supporting dynamic bottom-up assertions using any() and satisfies().", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
+35
-2
@@ -29,6 +29,8 @@ # deep-assert | ||
| Let'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()`. | ||
| ```js | ||
| import * as assert from "assert-deep" | ||
| assert.deepEquals(getUsers() , [ | ||
| assert.deepEquals(getUsers(), [ | ||
| { | ||
@@ -49,2 +51,4 @@ id: assert.any(), | ||
| Let'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. | ||
| ```js | ||
@@ -56,3 +60,3 @@ import * as assert from "assert-deep" | ||
| assert.deepEquals(getUsers() , [ | ||
| assert.deepEquals(getUsers(), [ | ||
| { | ||
@@ -71,4 +75,33 @@ id: assertUUID(), | ||
| ### Spreading any() | ||
| Normally `deepEquals()` will fail if there are unexpected properties on the tested object. We can use `any()` with the object spread operator to allow additional properties to be present. | ||
| `deepEquals()` will then only check the expected properties and ignore all other ones. | ||
| ```js | ||
| import * as assert from "assert-deep" | ||
| assert.deepEquals(getUsers()[0], { | ||
| name: "John Smith", | ||
| active: true, | ||
| ...assert.any() | ||
| }) | ||
| ``` | ||
| ### Recursive objects | ||
| ```js | ||
| import * as assert from "assert-deep" | ||
| const a = { foo: {} } | ||
| a.foo.parent = a.foo | ||
| assert.deepEquals(a, { | ||
| foo: assert.satisfies(foo => assert.deepEquals(foo, { parent: foo })) | ||
| }) | ||
| ``` | ||
| ## License | ||
| MIT |
19091
5.87%349
0.29%104
46.48%