chai-struct
TypeScript icon, indicating that this package has built-in type declarations

4.0.1 • Public • Published

chai-struct

Simple, readable, structural type assertions for Chai.

Build Status Coverage Status Greenkeeper badge dependencies Status devDependencies Status

Usage

Verify that data has a given structure.

import chai, { expect } from 'chai'
import { chaiStruct } from 'chai-struct'
 
chai.use(chaiStruct)
 
describe('my data', () => {
 
  const fanbois = {
    id: 1,
    groupName: 'JS Fanbois',
    members: [
      { username: 'brendaneich' },
      { username: 'douglascrockford' },
      { username: true } // <- this ain't right
    ]
  }
 
  it('has the correct structure?', () => {
    expect(fanbois).to.have.structure({
      id: Number,
      groupName: String,
      members: [{ username: String }]
    })
    /**
     * 1) my data has the correct structure?:
     * AssertionError: Unexpected structure:
     * {
     *   "members": {
     *     "2": {
     *       "username": {
     *         "actual": "Boolean",
     *         "expected": "String",
     *         "value": "true"
     *       }
     *     }
     *   }
     * }
     */
  })
 
})

Supports Optional, Nullable, and Any types from type-diff.

import { chaiStruct, Optional, Nullable, Any } from 'chai-struct'

Readme

Keywords

none

Package Sidebar

Install

npm i chai-struct

Weekly Downloads

3

Version

4.0.1

License

ISC

Unpacked Size

8.08 kB

Total Files

5

Last publish

Collaborators

  • thebearingedge