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 请求和问题。
许可证
MIT (c) 2013 Agile Diagnosis, Inc. 请参阅 LICENSE.md