npm

Join us for the "JavaScript Supply Chain Security" tech talk, presented by VP of Security, Adam Baldwin. 6/20 at 10am PT.Sign up here »

chai-struct

3.0.4 • Public • Published

chai-struct

Simple, readable, structural type comparisons for Chai

Build Status Coverage Status Greenkeeper badge

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'

install

npm i chai-struct

Downloadsweekly downloads

37

version

3.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability