Skip to content

Commit

Permalink
fix(prefer-spy-on): fix Cannot read property 'type' of undefined (#199)
Browse files Browse the repository at this point in the history
Fixes #198
  • Loading branch information
hanneslund authored and SimenB committed Nov 4, 2018
1 parent ae7aee9 commit 02cd21a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions rules/__tests__/prefer-spy-on.test.js
Expand Up @@ -13,6 +13,7 @@ ruleTester.run('prefer-spy-on', rule, {
valid: [
'Date.now = () => 10',
'window.fetch = jest.fn',
'Date.now = fn()',
'obj.mock = jest.something()',
'const mock = jest.fn()',
'mock = jest.fn()',
Expand Down
5 changes: 4 additions & 1 deletion rules/prefer-spy-on.js
Expand Up @@ -4,7 +4,10 @@ const getDocsUrl = require('./util').getDocsUrl;
const getNodeName = require('./util').getNodeName;

const getJestFnCall = node => {
if (node.type !== 'CallExpression' && node.type !== 'MemberExpression') {
if (
(node.type !== 'CallExpression' && node.type !== 'MemberExpression') ||
(node.callee && node.callee.type !== 'MemberExpression')
) {
return null;
}

Expand Down

0 comments on commit 02cd21a

Please sign in to comment.