Gathering detailed insights and metrics for deep-assert
Gathering detailed insights and metrics for deep-assert
Gathering detailed insights and metrics for deep-assert
Gathering detailed insights and metrics for deep-assert
🔍 Better deep-equals comparison, supporting custom property assertions and pretty diffs.
npm install deep-assert
Typescript
Module System
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3 Stars
17 Commits
2 Forks
2 Watchers
1 Branches
2 Contributors
Updated on Jan 12, 2022
Latest Version
0.3.0
Package Id
deep-assert@0.3.0
Unpacked Size
19.86 kB
Size
5.99 kB
File Count
11
NPM Version
8.1.0
Node Version
16.13.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
7
The most developer-friendly way to write assertions for large or complicated objects and arrays.
any()
and satisfies()
property matchers
npm install 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()
.
1import * as assert from "assert-deep" 2 3assert.deepEquals( 4 // Actual value: 5 { 6 id: Math.random(), 7 name: "John Smith", 8 meta: { 9 isActive: true, 10 lastLogin: new Date("2019-04-29T12:31:00") 11 } 12 }, 13 // Expectation: 14 { 15 id: assert.any(), 16 name: "John Smith", 17 meta: { 18 isActive: true, 19 lastLogin: new Date("2019-04-29T12:31:00") 20 } 21 } 22])
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.
1import * as assert from "assert-deep" 2 3const assertPositiveNumber = () => assert.satisfies(value => typeof value === "number" && value > 0) 4 5assert.deepEquals( 6 // Actual value: 7 { 8 id: Math.random(), 9 name: "John Smith", 10 meta: { 11 isActive: true, 12 lastLogin: new Date("2019-04-29T12:31:00") 13 } 14 }, 15 // Expectation: 16 { 17 id: assertPositiveNumber(), 18 name: "John Smith", 19 meta: { 20 isActive: true, 21 lastLogin: new Date("2019-04-29T12:31:00") 22 } 23 } 24])
Normally 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.
deepEquals()
will then only check the expected properties and ignore all other ones.
1import * as assert from "assert-deep" 2 3assert.deepEquals( 4 // Actual value: 5 { 6 id: Math.random(), 7 name: "John Smith", 8 meta: { 9 isActive: true, 10 lastLogin: new Date("2019-04-29T12:31:00") 11 } 12 }, 13 // Expectation: 14 { 15 id: assert.any(), 16 name: "John Smith", 17 ...assert.any() 18 } 19])
You can call deepEquals()
in a custom satisfies()
as well. This way you can easily test recursive data structures, for instance.
1import * as assert from "assert-deep"
2
3const actual = { foo: {} }
4actual.foo.parent = actual.foo
5
6assert.deepEquals(actual, {
7 foo: assert.satisfies(foo => assert.deepEquals(foo, { parent: foo }))
8})
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
6 existing vulnerabilities detected
Details
Reason
Found 1/17 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More