Skip to content

node module: chai assertions about an object's interface

License

Notifications You must be signed in to change notification settings

keithamus/chai-interface

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chai-interface

chai assertions about an object's interface

installation

$ npm install chai-interface

usage

    var chai = require('chai')
    chai.should()
    chai.use(require('chai-interface'))

    var foo = {
      bar: true,
      baz: 'green',
      qux: 37,
      quack: function () {},
      ducks: [1, 2, 3]
    }

    foo.should.have.interface({
      bar: Boolean,
      baz: String,
      qux: Number,
      quack: Function,
      ducks: Array
    })

Also, more complex, nested objects!

    var user = {
      name: {
        first: 'Betty',
        last: 'Dodson'
      },
      emails: {
        work: '[email protected]',
        home: '[email protected]',
        school: '[email protected]'
      }
    }

    user.should.have.interface({
      name: {
        first: String,
        last: String
      },
      emails: {
        work: String,
        home: String,
        school: String
      }
    })

example error message

Interface not as expected:
{
  "bars": {
    "actual": "Array<String>",
    "expected": "Array<Number>",
    "actualValue": [
      "a",
      "b",
      "c"
    ]
  }
}

by the power of tracery

chai-interface does interface checking using tracery

contributors

jden [email protected] @leJDen

Please submit pull requests and issues through github.

license

MIT (c) 2013 Agile Diagnosis, Inc. see LICENSE.md

About

node module: chai assertions about an object's interface

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%