|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const expectCase = node => |
| 4 | + node.callee.name === 'expect' && |
| 5 | + node.arguments.length == 1 && |
| 6 | + node.parent && |
| 7 | + node.parent.type === 'MemberExpression' && |
| 8 | + node.parent.parent; |
| 9 | + |
| 10 | +const expectNotCase = node => |
| 11 | + expectCase(node) && |
| 12 | + node.parent.parent.type === 'MemberExpression' && |
| 13 | + methodName(node) === 'not'; |
| 14 | + |
| 15 | +const expectResolveCase = node => |
| 16 | + expectCase(node) && |
| 17 | + node.parent.parent.type === 'MemberExpression' && |
| 18 | + methodName(node) === 'resolve'; |
| 19 | + |
| 20 | +const expectRejectCase = node => |
| 21 | + expectCase(node) && |
| 22 | + node.parent.parent.type === 'MemberExpression' && |
| 23 | + methodName(node) === 'reject'; |
| 24 | + |
| 25 | +const expectToBeCase = (node, arg) => |
| 26 | + !(expectNotCase(node) || expectResolveCase(node) || expectRejectCase(node)) && |
| 27 | + expectCase(node) && |
| 28 | + methodName(node) === 'toBe' && |
| 29 | + argument(node).value === arg; |
| 30 | + |
| 31 | +const expectNotToBeCase = (node, arg) => |
| 32 | + expectNotCase(node) && |
| 33 | + methodName2(node) === 'toBe' && |
| 34 | + argument2(node).value === arg; |
| 35 | + |
| 36 | +const expectToEqualCase = (node, arg) => |
| 37 | + !(expectNotCase(node) || expectResolveCase(node) || expectRejectCase(node)) && |
| 38 | + expectCase(node) && |
| 39 | + methodName(node) === 'toEqual' && |
| 40 | + argument(node).value === arg; |
| 41 | + |
| 42 | +const expectNotToEqualCase = (node, arg) => |
| 43 | + expectNotCase(node) && |
| 44 | + methodName2(node) === 'toEqual' && |
| 45 | + argument2(node).value === arg; |
| 46 | + |
| 47 | +const expectToBeUndefinedCase = node => |
| 48 | + !(expectNotCase(node) || expectResolveCase(node) || expectRejectCase(node)) && |
| 49 | + expectCase(node) && |
| 50 | + methodName(node) === 'toBeUndefined'; |
| 51 | + |
| 52 | +const expectNotToBeUndefinedCase = node => |
| 53 | + expectNotCase(node) && methodName2(node) === 'toBeUndefined'; |
| 54 | + |
| 55 | +const method = node => node.parent.property; |
| 56 | + |
| 57 | +const method2 = node => node.parent.parent.property; |
| 58 | + |
| 59 | +const methodName = node => method(node).name; |
| 60 | + |
| 61 | +const methodName2 = node => method2(node).name; |
| 62 | + |
| 63 | +const argument = node => node.parent.parent.arguments[0]; |
| 64 | + |
| 65 | +const argument2 = node => node.parent.parent.parent.arguments[0]; |
| 66 | + |
| 67 | +module.exports = { |
| 68 | + method: method, |
| 69 | + method2: method2, |
| 70 | + argument: argument, |
| 71 | + argument2: argument2, |
| 72 | + expectCase: expectCase, |
| 73 | + expectNotCase: expectNotCase, |
| 74 | + expectResolveCase: expectResolveCase, |
| 75 | + expectRejectCase: expectRejectCase, |
| 76 | + expectToBeCase: expectToBeCase, |
| 77 | + expectNotToBeCase: expectNotToBeCase, |
| 78 | + expectToEqualCase: expectToEqualCase, |
| 79 | + expectNotToEqualCase: expectNotToEqualCase, |
| 80 | + expectToBeUndefinedCase: expectToBeUndefinedCase, |
| 81 | + expectNotToBeUndefinedCase: expectNotToBeUndefinedCase, |
| 82 | +}; |
0 commit comments