-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
29 lines (23 loc) · 800 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var tracery = require('tracery')
var diff = require('tracery/diff')
function chaiInterface(chai, utils) {
var Assertion = chai.Assertion;
var assert = chai.assert;
utils.addMethod(Assertion.prototype, 'interface', function(interfaceMap) {
// map is an object map with property names as keys and strings for
// typeof checks or a nested interfaceMap
assert(typeof this._obj === 'object' || typeof this._obj === 'function', "object or function expected")
var hasInterface = tracery(interfaceMap)
assert(
hasInterface(this._obj),
format(diff(interfaceMap, this._obj))
)
})
}
function format (diff) {
var str = 'Interface not as expected:\n'
// pretty print json
str += JSON.stringify(diff, null, 2)
return str;
}
module.exports = chaiInterface