Skip to content

Commit

Permalink
fix(no-mocks-import): do not crash on dynamic require (#250)
Browse files Browse the repository at this point in the history
Fixes #249

Co-authored-by: Martin Zlámal <mrtnzlml@gmail.com>
  • Loading branch information
2 people authored and SimenB committed Apr 25, 2019
1 parent d0a48e1 commit bdc0bb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions rules/__tests__/no-mocks-import.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ruleTester.run('no-mocks-import', rule, {
'require("./x__mocks__")',
'require("./x__mocks__/x")',
'require()',
'var path = "./__mocks__.js"; require(path)',
'entirelyDifferent(fn)',
],
invalid: [
Expand Down
6 changes: 5 additions & 1 deletion rules/no-mocks-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ module.exports = {
}
},
'CallExpression[callee.name="require"]'(node) {
if (node.arguments.length && isMockPath(node.arguments[0].value)) {
if (
node.arguments.length &&
node.arguments[0].value &&
isMockPath(node.arguments[0].value)
) {
context.report({
loc: node.arguments[0].loc,
message,
Expand Down

0 comments on commit bdc0bb0

Please sign in to comment.