1 | 'use strict';
|
2 |
|
3 | const { getDocsUrl, isFunction, isTestCase } = require('./util');
|
4 |
|
5 | const MESSAGE = 'Jest tests should not return a value.';
|
6 | const RETURN_STATEMENT = 'ReturnStatement';
|
7 | const BLOCK_STATEMENT = 'BlockStatement';
|
8 |
|
9 | const getBody = args => {
|
10 | if (
|
11 | args.length > 1 &&
|
12 | isFunction(args[1]) &&
|
13 | args[1].body.type === BLOCK_STATEMENT
|
14 | ) {
|
15 | return args[1].body.body;
|
16 | }
|
17 | return [];
|
18 | };
|
19 |
|
20 | module.exports = {
|
21 | meta: {
|
22 | docs: {
|
23 | url: getDocsUrl(__filename),
|
24 | },
|
25 | },
|
26 | create(context) {
|
27 | return {
|
28 | CallExpression(node) {
|
29 | if (!isTestCase(node)) return;
|
30 | const body = getBody(node.arguments);
|
31 | const returnStmt = body.find(t => t.type === RETURN_STATEMENT);
|
32 | if (!returnStmt) return;
|
33 |
|
34 | context.report({
|
35 | message: MESSAGE,
|
36 | node: returnStmt,
|
37 | });
|
38 | },
|
39 | };
|
40 | },
|
41 | };
|