chai-structured-like

1.1.0 • Public • Published

chai-structured-like

Build Status Coverage Status npm version

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] })

Dependents (0)

Package Sidebar

Install

npm i chai-structured-like

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

50 kB

Total Files

21

Last publish

Collaborators

  • xasdx