Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thebearingedge/chai-struct
❗️Chai assertion for object structures.
https://github.com/thebearingedge/chai-struct
Last synced: 28 days ago
JSON representation
❗️Chai assertion for object structures.
- Host: GitHub
- URL: https://github.com/thebearingedge/chai-struct
- Owner: thebearingedge
- License: mit
- Created: 2016-07-30T18:13:48.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-20T01:03:34.000Z (over 4 years ago)
- Last Synced: 2024-10-04T07:34:19.673Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 368 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
chai-struct
--Simple, readable, structural type assertions for Chai.
[![Build Status](https://travis-ci.org/thebearingedge/chai-struct.svg?branch=master)](https://travis-ci.org/thebearingedge/chai-struct.svg?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/thebearingedge/chai-struct/badge.svg?branch=master)](https://coveralls.io/github/thebearingedge/chai-struct?branch=master)
[![Greenkeeper badge](https://badges.greenkeeper.io/thebearingedge/chai-struct.svg)](https://greenkeeper.io/)
[![dependencies Status](https://david-dm.org/thebearingedge/chai-struct/status.svg)](https://david-dm.org/thebearingedge/chai-struct)
[![devDependencies Status](https://david-dm.org/thebearingedge/chai-struct/dev-status.svg)](https://david-dm.org/thebearingedge/chai-struct?type=dev)### Usage
Verify that data has a given structure.
```javascript
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`](https://github.com/thebearingedge/type-diff).
```js
import { chaiStruct, Optional, Nullable, Any } from 'chai-struct'
```