Skip to content

Commit bdc0bb0

Browse files
jeysalmrtnzlml
authored andcommitted
fix(no-mocks-import): do not crash on dynamic require (#250)
Fixes #249 Co-authored-by: Martin Zlámal <[email protected]>
1 parent d0a48e1 commit bdc0bb0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

rules/__tests__/no-mocks-import.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ruleTester.run('no-mocks-import', rule, {
1818
'require("./x__mocks__")',
1919
'require("./x__mocks__/x")',
2020
'require()',
21+
'var path = "./__mocks__.js"; require(path)',
2122
'entirelyDifferent(fn)',
2223
],
2324
invalid: [

rules/no-mocks-import.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ module.exports = {
2222
}
2323
},
2424
'CallExpression[callee.name="require"]'(node) {
25-
if (node.arguments.length && isMockPath(node.arguments[0].value)) {
25+
if (
26+
node.arguments.length &&
27+
node.arguments[0].value &&
28+
isMockPath(node.arguments[0].value)
29+
) {
2630
context.report({
2731
loc: node.arguments[0].loc,
2832
message,

0 commit comments

Comments
 (0)