Skip to content

Commit

Permalink
fix: add warning to describe (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlmacdonald authored and SimenB committed Feb 10, 2018
1 parent 883a842 commit 18c97de
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
26 changes: 25 additions & 1 deletion rules/__tests__/valid-describe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const ruleTester = new RuleTester({

ruleTester.run('valid-describe', rules['valid-describe'], {
valid: [
'describe("foo")',
'describe("foo", function() {})',
'describe("foo", () => {})',
'xdescribe("foo", () => {})',
Expand All @@ -36,6 +35,31 @@ ruleTester.run('valid-describe', rules['valid-describe'], {
`,
],
invalid: [
{
code: 'describe(() => {})',
errors: [
{
message: 'First argument must be name',
line: 1,
column: 10,
},
{
message: 'Describe requires name and callback arguments',
line: 1,
column: 10,
},
],
},
{
code: 'describe("foo")',
errors: [
{
message: 'Describe requires name and callback arguments',
line: 1,
column: 10,
},
],
},
{
code: 'describe("foo", async () => {})',
errors: [{ message: 'No async describe callback', line: 1, column: 17 }],
Expand Down
13 changes: 13 additions & 0 deletions rules/valid-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ module.exports = {
return {
CallExpression(node) {
if (isDescribe(node)) {
const name = node.arguments[0];
const callbackFunction = node.arguments[1];
if (name.type !== 'Literal') {
context.report({
message: 'First argument must be name',
loc: paramsLocation(node.arguments),
});
}
if (callbackFunction === undefined) {
context.report({
message: 'Describe requires name and callback arguments',
loc: paramsLocation(node.arguments),
});
}
if (callbackFunction && isFunction(callbackFunction)) {
if (isAsync(callbackFunction)) {
context.report({
Expand Down

0 comments on commit 18c97de

Please # to comment.