-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
valid-expect.js
47 lines (43 loc) · 1.26 KB
/
valid-expect.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
39
40
41
42
43
44
45
46
47
'use strict'
/**
* DEPRECATED use expect-matcher and expect-single-argument rules instead
* @fileoverview Enforce valid expect() usage
* @author Alexander Afanasyev
*/
module.exports = function (context) {
return {
CallExpression: function (node) {
if (node.callee.name === 'expect') {
// checking "expect()" arguments
if (node.arguments.length > 1) {
context.report({
message: 'More than one argument passed to expect()',
node
})
} else if (node.arguments.length === 0) {
context.report({
message: 'No arguments passed to expect()',
node
})
}
// matcher was not called
if (node.parent && node.parent.parent && node.parent.parent.type !== 'CallExpression' &&
node.parent.parent.type !== 'MemberExpression') {
context.report({
message: 'Matcher was not called',
node
})
}
}
},
// nothing called on "expect()"
'CallExpression:exit': function (node) {
if (node.callee.name === 'expect' && node.parent.type === 'ExpressionStatement') {
context.report({
message: 'Nothing called on expect()',
node
})
}
}
}
}