Installations
npm install deep-assert
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.13.0
NPM Version
8.1.0
Score
71.5
Supply Chain
98.3
Quality
75.2
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
andywer
Download Statistics
Total Downloads
24,150
Last Day
2
Last Week
3
Last Month
54
Last Year
22,424
GitHub Statistics
3 Stars
17 Commits
2 Forks
3 Watching
1 Branches
2 Contributors
Bundle Size
5.80 kB
Minified
2.14 kB
Minified + Gzipped
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
24,150
Last day
0%
2
Compared to previous day
Last week
-25%
3
Compared to previous week
Last month
-97.4%
54
Compared to previous month
Last year
6,094.5%
22,424
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
7
deep-assert
The most developer-friendly way to write assertions for large or complicated objects and arrays.
- Use
any()
andsatisfies()
property matchers - Short, but precise diffs, even for large nested objects
- Works with objects, arrays, dates, buffers, and more
- Write custom property assertions
- Zero dependencies
Installation
npm install deep-assert
Usage
Basic
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])
Custom assertions
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])
Spreading any()
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])
Recursive objects
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})
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
5 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
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
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 2 are checked with a SAST tool
Score
2.4
/10
Last Scanned on 2025-02-03
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