Skip to content

Commit

Permalink
fix: supporting arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DianaSuvorova authored and Nicolas Fernandez committed Jul 28, 2017
1 parent a1c01e2 commit dde1f7f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/rules/no-suite-callback-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ module.exports = function (context) {
if (suiteRegexp.test(node.callee.name) && node.arguments.length > 1) {
var arg = node.arguments[1]

if (arg.type === 'FunctionExpression' && arg.params.length) {
if ((arg.type === 'FunctionExpression' || arg.type === 'ArrowFunctionExpression') &&
arg.params.length
) {
context.report({
message: "Unexpected argument in suite's callback",
node
Expand Down
50 changes: 46 additions & 4 deletions test/rules/no-suite-callback-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@

var rule = require('../../lib/rules/no-suite-callback-args')
var RuleTester = require('eslint').RuleTester
var linesToCode = require('../helpers/lines_to_code')

var eslintTester = new RuleTester()
const parserOptions = {
ecmaVersion: 8
}

var eslintTester = new RuleTester({parserOptions})

eslintTester.run('describe-with-done', rule, {
valid: [
Expand All @@ -13,7 +18,19 @@ eslintTester.run('describe-with-done', rule, {
'xdescribe("My suite", function() {});',
'describe("My suite", function() {\nit("A spec", function() {});\n});',
'describe("My suite", function() {\nit("A spec", function(done) {});\n});',
'describe("My suite", function() {\nit("A spec", function(done) {\ndone();\n});\n });'
'describe("My suite", function() {\nit("A spec", function(done) {\ndone();\n});\n });',
linesToCode([
'describe("", () => {',
' it("", () => {',
' });',
'});'
]),
linesToCode([
'describe("", () => {',
' it("", (done) => {',
' });',
'});'
])
],

invalid: [
Expand Down Expand Up @@ -72,6 +89,31 @@ eslintTester.run('describe-with-done', rule, {
message: "Unexpected argument in suite's callback"
}
]
}
]
},
{
code: linesToCode([
'describe("", (done) => {',
' it("", (done) => {',
' });',
'});'
]),
errors: [
{
message: "Unexpected argument in suite's callback"
}
]
},
{
code: linesToCode([
'describe("", () => {',
' describe("", (done) => {',
' });',
'});'
]),
errors: [
{
message: "Unexpected argument in suite's callback"
}
]
}]
})

0 comments on commit dde1f7f

Please sign in to comment.