Gathering detailed insights and metrics for chai-better-shallow-deep-equal
Gathering detailed insights and metrics for chai-better-shallow-deep-equal
Gathering detailed insights and metrics for chai-better-shallow-deep-equal
Gathering detailed insights and metrics for chai-better-shallow-deep-equal
npm install chai-better-shallow-deep-equal
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3 Stars
27 Commits
1 Watchers
2 Branches
1 Contributors
Updated on May 19, 2021
Latest Version
1.1.1
Package Id
chai-better-shallow-deep-equal@1.1.1
Unpacked Size
10.29 kB
Size
4.26 kB
File Count
5
NPM Version
6.13.4
Node Version
10.19.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
3
1
This module provides a drop-in replacement shallowDeepEqual
assertion for chai that uses strict
semantics and an intuitive output diff.
Under the hood the library wraps the Unexpected library, specifically making use of the structural "to satisfy" assertion.
Once installed the plugin can be simply imported and used as a plugin:
1const chai = require("chai"); 2const expect = chai.expect; 3 4chai.use(require("chai-better-shallow-deep-equal"));
An additional .shallowDeepEqual()
assertion is then available for use and
on error an informative diff will be printed:
1expect({ foo: true, bar: 0 }).to.shallowDeepEqual({ foo: true, bar: 1 });
expected { foo: true, bar: 0 } to satisfy { foo: true, bar: 1 }
{
foo: true,
bar: 0 // should equal 1
}
The assertion works with all three chai APIs: expect
, should
and assert
.
The plugin has support for structurally comparing both Map and Set objects:
1expect( 2 new Map([ 3 ["foo", 1], 4 ["bar", false] 5 ]) 6).to.shallowDeepEqual( 7 new Map([ 8 ["foo", 1], 9 ["bar", true] 10 ]) 11);
expected new Map[ ['foo', 1], ['bar', false] ])
to satisfy new Map[ ['foo', 1], ['bar', true] ])
new Map[
['foo', 1,]
['bar',
false // should equal true
]
])
1expect(new Set(["foo", "baz"])).to.shallowDeepEqual( 2 new Set(["foo", "bar"]) 3);
expected new Set([ 'foo', 'baz' ]) to satisfy new Set([ 'foo', 'bar' ])
new Set([
'foo',
'baz' // should be removed
// missing 'bar'
])
Sometimes it can be beneficial to identify certain types within
the test suite - perhaps to customise their display or to treat
them otherwise differently. This can be achieved by using the
addType()
API:
1const chaiBetterShallowDeepEqual = require("chai-better-shallow-deep-equal");
2
3chaiBetterShallowDeepEqual.addType({
4 name: "CustomDate",
5 base: "date",
6 identify: obj => obj && obj._isCustomDate
7});
In the example above, we are trying to single out certain objects that occur within a hypthetical test suite that use custom dates by checking whether they have an "isCustomDate" property.
Given our definition of the identify()
method above, when the
plugin encounters such objects it will think of them as CustomDate
and be aware that they extend the behavior of the builtin date type.
This API accepts the same options as the Unexpected addType() method. Please consult the link for more detailed description.
With the availablity of custom types are in the picture, one common desire is to allow customising the way those identified types are matched.
By default only alike types are compared, but suppose that within
our tests we want to allow comparing any CustomDate
object against
a, ISO time string.
Let's stick with the exmaple from our earlier hypothetical - we can
define allowing the comparison using the addMatch()
API:
1chaiBetterShallowDeepEqual.addMatch({
2 leftType: "CustomDate",
3 rightType: "string",
4 handler: (lhs, rhs) => [lhs.toISOString(), rhs]
5});
What we've defined here is when we see a CustomDate
being compared
to a string, to instead first convert it to an ISO string and then do
the comparison. In the test suite, the effect is to allow expecations
to be defined in a way that is much more easily read:
1const fooDate = new Date(1583947016326); 2 3expect({ fooDate }).to.shallowDeepEqual({ 4 fooDate: "2020-03-11T17:16:56.326Z" 5});
expected { fooDate: new Date('2020-03-11T17:16:56.326Z') }
to satisfy { fooDate: '2020-03-11T17:16:56.326Z' }
{
fooDate: new Date('2020-03-11T17:16:56.326Z') // should equal '2020-03-11T17:16:56.326Z'
}
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/27 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 SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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
Score
Last Scanned on 2025-07-14
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