Skip to content

Commit

Permalink
Fix: Check for arrow functions in no-loose-assertions & no-assert-ok
Browse files Browse the repository at this point in the history
Both of these rules use utils.createAssertionCheck, which only
checks for non-arrow functions.

Fixes #213
  • Loading branch information
edg2s committed Nov 2, 2021
1 parent 34968fe commit 4ddda0d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ exports.isSkip = function (calleeNode) {

exports.getAssertContextNameForTest = function (argumentsNodes) {
const functionExpr = argumentsNodes.find(function (argNode) {
return argNode.type === "FunctionExpression";
return argNode.type === "FunctionExpression" || argNode.type === "ArrowFunctionExpression";
});

return this.getAssertContextName(functionExpr);
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-assert-ok.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ ruleTester.run("no-assert-ok", rule, {
}
}]
},
{
code: "QUnit.test('Name', (assert) => { assert.ok(a); });",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpectedLocalOkNotOk",
data: {
assertVar: "assert",
assertion: "ok"
}
}]
},
{
code: "QUnit.test('Name', function (foo) { foo.ok(a); });",
errors: [{
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-loose-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ ruleTester.run("no-loose-assertions", rule, {
}
}]
},
{
code: "QUnit.test('Name', (assert) => { assert.ok(a); });",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "unexpectedLocalLooseAssertion",
data: {
assertVar: "assert",
assertion: "ok"
}
}]
},
{
code: "QUnit.test('Name', function (foo) { foo.ok(a); });",
errors: [{
Expand Down

0 comments on commit 4ddda0d

Please sign in to comment.