From 7ca76fa581ade1a9a67dc1765e0f241729142d86 Mon Sep 17 00:00:00 2001 From: tushardhole Date: Thu, 22 Feb 2018 17:19:32 +0530 Subject: [PATCH] chore: get to 100% test coverage (#89) * test: add missing branch covergae for valid-expect-in-promise * fix: add valid describe scenario where second srgument is not function * test: add missing branch covergae for util.js * test: bumping up branch coverage to 100 * test: adding missing test in prefer-to-have-length --- package.json | 2 +- rules/__tests__/prefer-to-have-length.test.js | 2 + rules/__tests__/valid-describe.test.js | 10 +++++ .../__tests__/valid-expect-in-promise.test.js | 1 + rules/valid-describe.js | 42 ++++++++++--------- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 74ebab6e8..5b7ef617f 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "jest": { "coverageThreshold": { "global": { - "branches": 98, + "branches": 100, "functions": 100, "lines": 100, "statements": 100 diff --git a/rules/__tests__/prefer-to-have-length.test.js b/rules/__tests__/prefer-to-have-length.test.js index 0e20f4f26..fe4f34264 100644 --- a/rules/__tests__/prefer-to-have-length.test.js +++ b/rules/__tests__/prefer-to-have-length.test.js @@ -10,6 +10,8 @@ ruleTester.run('prefer-to-have-length', rule, { 'expect(files).toHaveLength(1);', "expect(files.name).toBe('file');", 'expect(result).toBe(true);', + `expect(user.getUserName(5)).resolves.toEqual('Paul')`, + `expect(user.getUserName(5)).rejects.toEqual('Paul')`, ], invalid: [ diff --git a/rules/__tests__/valid-describe.test.js b/rules/__tests__/valid-describe.test.js index d96c2d4d5..2db4a2c3d 100644 --- a/rules/__tests__/valid-describe.test.js +++ b/rules/__tests__/valid-describe.test.js @@ -61,6 +61,16 @@ ruleTester.run('valid-describe', rule, { }, ], }, + { + code: 'describe("foo", "foo2")', + errors: [ + { + message: 'Second argument must be function', + line: 1, + column: 10, + }, + ], + }, { code: 'describe("foo", async () => {})', errors: [{ message: 'No async describe callback', line: 1, column: 17 }], diff --git a/rules/__tests__/valid-expect-in-promise.test.js b/rules/__tests__/valid-expect-in-promise.test.js index d8333dd5d..32e294c61 100644 --- a/rules/__tests__/valid-expect-in-promise.test.js +++ b/rules/__tests__/valid-expect-in-promise.test.js @@ -166,6 +166,7 @@ ruleTester.run('valid-expect-in-promise', rule, { code: ` test('invalid return', () => { const promise = something().then(value => { + const foo = "foo"; return expect(value).toBe('red'); }); }); diff --git a/rules/valid-describe.js b/rules/valid-describe.js index c01cf4992..a44412c27 100644 --- a/rules/valid-describe.js +++ b/rules/valid-describe.js @@ -51,28 +51,32 @@ module.exports = { loc: paramsLocation(node.arguments), }); } - if (isFunction(callbackFunction)) { - if (isAsync(callbackFunction)) { - context.report({ - message: 'No async describe callback', - node: callbackFunction, - }); - } - if (hasParams(callbackFunction)) { + if (!isFunction(callbackFunction)) { + return context.report({ + message: 'Second argument must be function', + loc: paramsLocation(node.arguments), + }); + } + if (isAsync(callbackFunction)) { + context.report({ + message: 'No async describe callback', + node: callbackFunction, + }); + } + if (hasParams(callbackFunction)) { + context.report({ + message: 'Unexpected argument(s) in describe callback', + loc: paramsLocation(callbackFunction.params), + }); + } + callbackFunction.body.body.forEach(node => { + if (node.type === 'ReturnStatement') { context.report({ - message: 'Unexpected argument(s) in describe callback', - loc: paramsLocation(callbackFunction.params), + message: 'Unexpected return statement in describe callback', + node, }); } - callbackFunction.body.body.forEach(node => { - if (node.type === 'ReturnStatement') { - context.report({ - message: 'Unexpected return statement in describe callback', - node, - }); - } - }); - } + }); } }, };