chai-structured-like
v1.1.0
Published
A Chai plugin with chainable helper assertions, comparing the structure of two objects
Downloads
9
Maintainers
Readme
chai-structured-like
A Chai plugin with chainable helper assertions, comparing the structure of two objects
What it does
Asserts that two objects has the same structure. The structure of objects are equal when:
- The objects have the same number of properties
- The properties match by name
- The properties match by type
So { a: 0, b: true, c: "hi" }
and { a: 0, b: false, c: "hello" }
are considered structurally equal
How to install it
npm install chai-structured-like --save
How to use it
You can compare the structure of two objects:
expect({ n: 0, m: true, s: "hi" }).to.be.structuredLike({ n: 1, m: false, s: "hey" })
Or even compare the structure of nested objects:
expect({ a: 1, b: { c: "" }}).to.be.structuredLike({ a: 123, b: { c: "str" }})
Or use the shorter structured
alias
expect({ a: 1, b: [] }).to.be.structured({ a: 0, b: [true] })