Skip to content

Commit

Permalink
chore: get to 100% test coverage (jest-community#89)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tushardhole authored and SimenB committed Feb 22, 2018
1 parent 62d4660 commit 7ca76fa
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -53,7 +53,7 @@
"jest": {
"coverageThreshold": {
"global": {
"branches": 98,
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
Expand Down
2 changes: 2 additions & 0 deletions rules/__tests__/prefer-to-have-length.test.js
Expand Up @@ -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: [
Expand Down
10 changes: 10 additions & 0 deletions rules/__tests__/valid-describe.test.js
Expand Up @@ -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 }],
Expand Down
1 change: 1 addition & 0 deletions rules/__tests__/valid-expect-in-promise.test.js
Expand Up @@ -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');
});
});
Expand Down
42 changes: 23 additions & 19 deletions rules/valid-describe.js
Expand Up @@ -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,
});
}
});
}
});
}
},
};
Expand Down

0 comments on commit 7ca76fa

Please sign in to comment.