New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

deep-assert

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deep-assert - npm Package Compare versions

Comparing version
0.1.0
to
0.2.0
+1
-1
dist/index.d.ts
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 };

@@ -14,4 +14,5 @@ "use strict";

}
return true;
}
exports.default = deepEquals;
exports.deepEquals = deepEquals;
{
"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",

@@ -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