-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (34 loc) · 957 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
30
31
32
33
34
35
36
37
38
module.exports = function chaiLint(chai, utils) {
var standardMethods = [
'ok',
'true',
'false',
'null',
'undefined',
'empty',
'arguments'
];
var sinonMethods = [
'called',
'calledOnce',
'calledTwice',
'calledThrice',
'calledWithNew',
];
addMethods(standardMethods, 'be');
addMethods(sinonMethods, 'been');
addMethod('exist', 'toExist');
function addMethods(methods, prefix) {
for (var i = methods.length - 1; i >= 0; i--) {
var property = methods[i];
var name = prefix + property[0].toUpperCase() + property.slice(1);
addMethod(methods[i], name);
}
}
function addMethod(property, name) {
chai.Assertion.addMethod(name, function() {
var obj = utils.flag(this, 'object');
new chai.Assertion(obj).to.be[property];
});
}
};