Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add warning to describe #65

Merged
merged 1 commit into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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