chai-interface

關於物件介面的 Chai 斷言

安裝

$ npm install chai-interface

用法

    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
    })

而且,支援更複雜的巢狀物件!

    var user = {
      name: {
        first: 'Betty',
        last: 'Dodson'
      },
      emails: {
        work: 'b.dodson@megacorp.com',
        home: 'butterflychica947@lol.com',
        school: 'bdodso4@stateu.edu'
      }
    }

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

範例錯誤訊息

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

基於 tracery 的強大功能

chai-interface 使用 tracery 進行介面檢查

貢獻者

jden jason@denizac.org @leJDen

請透過 github 提交 Pull Request 和 Issue。

授權條款

MIT (c) 2013 Agile Diagnosis, Inc. 請參閱 LICENSE.md