4.0.1 • Published 4 years ago

chai-struct v4.0.1

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

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'
4.0.1

4 years ago

4.0.0

4 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

7 years ago

2.1.1

7 years ago

2.1.0

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago