deep-assert

Providing a better deep-equals assertion experience.
- Easily write object and array expectations, with
any() and satisfies()
- Create your own custom assertions
- Short, but precise diffs, even for large nested objects
- Works with objects, arrays, dates, buffers, etc
- Zero dependencies
Installation
npm install deep-assert
Usage
Basic
import * as assert from "assert-deep"
assert.deepEquals(getUsers() , [
{
id: assert.any(),
name: "John Smith",
active: true
},
{
id: assert.any(),
name: "Jane Smith",
active: false
}
])
Custom assertions
import * as assert from "assert-deep"
const uuidRegex = /^[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}$/
const assertUUID = assert.satisfies(value => typeof value === "string" && value.match(uuidRegex))
assert.deepEquals(getUsers() , [
{
id: assertUUID(),
name: "John Smith",
active: true
},
{
id: assertUUID(),
name: "Jane Smith",
active: false
}
])
License
MIT