Skip to content

thebearingedge/chai-struct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'

About

❗️Chai assertion for object structures.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published