Shallow deep equal almost assertion for chai
npm install chai-shallow-deep-almost-equalIt's a fork of https://github.com/michelsalib/chai-shallow-deep-equal which adds .001 float treshold almost-equality feature.
Will shallowly perform a deep almost equal assertion. In other terms is consist of checking that an object, or objects graph, is contained within another one (see examples bellow).


``html`
`javascript`
var chai = require('chai');
chai.use(require('chai-shallow-deep-almost-equal'));
ShallowDeepAlmostEqual is available for all chai assertion styles:
`javascript
var a = {x: 10, y: 10};
var b = {x: 10.001};
a.should.ShallowDeepAlmostEqual(b);
expect(a).to.ShallowDeepAlmostEqual(b);
assert.ShallowDeepAlmostEqual(a, b);
`
`javascript
assert.ShallowDeepAlmostEqual({x: 10, y: 10}, {x: 10.001}); // true
assert.ShallowDeepAlmostEqual({x: 10, y: 10}, {x: 9.999}); // true
// assert.ShallowDeepAlmostEqual({x: 10, y: 10}, {x: 9.9}); // fails
// the rest are the original shallowDeepEqualTests
assert.ShallowDeepAlmostEqual({
name: 'Michel',
language: 'javascript',
tags: [
'developer',
'gamer'
]},
{
name: 'Michel',
tags: [
'developer'
]}); // true
assert.ShallowDeepAlmostEqual([
{brand: 'apple', color: 'red'},
{brand: 'samsung', color: 'blue'},
],
{
length: 2,
0: {color: 'red'},
1: {brand: 'samsung'},
}); // true
assert.ShallowDeepAlmostEqual({
name: 'Michel',
age: undefined
},
{
name: 'Michel',
age: 37
}); // false (age should not be defined)
``