4.0.1 • Published 5 years ago
chai-struct v4.0.1
chai-struct
Simple, readable, structural type assertions for Chai.
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
5 years ago
4.0.0
5 years ago
3.0.4
8 years ago
3.0.3
8 years ago
3.0.2
8 years ago
3.0.1
8 years ago
3.0.0
8 years ago
2.1.1
9 years ago
2.1.0
9 years ago
2.0.1
9 years ago
2.0.0
9 years ago
1.0.7
9 years ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
9 years ago
1.0.0
9 years ago