Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefer-spy-on - Cannot read property 'type' of undefined #198

Closed
lukeapage opened this issue Nov 4, 2018 · 1 comment · Fixed by #199
Closed

prefer-spy-on - Cannot read property 'type' of undefined #198

lukeapage opened this issue Nov 4, 2018 · 1 comment · Fixed by #199
Labels

Comments

@lukeapage
Copy link
Contributor

TypeError: Cannot read property 'type' of undefined
  at getJestFnCall (C:\git\test\node_modules\eslint-plugin-jest\rules\prefer-spy-on.js:13:11)
  at AssignmentExpression (C:\git\test\node_modules\eslint-plugin-jest\rules\prefer-spy-on.js:35:28)

error is in here:

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

  const obj = node.callee ? node.callee.object : node.object;
  
  if (!obj) {
      console.log(node);
  }

  if (obj.type === 'Identifier') {
    return node.type === 'CallExpression' &&
      getNodeName(node.callee) === 'jest.fn'
      ? node
      : null;
  }

  return getJestFnCall(obj);
};

(edited with a console log)
which outputs:

Node {
  type: 'CallExpression',
  start: 5918,
  end: 5937,
  loc:
   SourceLocation {
     start: Position { line: 158, column: 35 },
     end: Position { line: 158, column: 54 } },
  range: [ 5918, 5937 ],
  callee:
   Node {
     type: 'Identifier',
     start: 5918,
     end: 5932,
     loc:
      SourceLocation {
        start: [Object],
        end: [Object],
        identifierName: 'mockTradeModel' },
     range: [ 5918, 5932 ],
     name: 'mockTradeModel',
     _babelType: 'Identifier',
     parent: [Circular] },
  arguments:
   [ Node {
       type: 'Literal',
       start: 5933,
       end: 5936,
       loc: [Object],
       range: [Array],
       value: 500,
       raw: '500',
       _babelType: 'Literal',
       parent: [Circular] } ],
  _babelType: 'CallExpression',
  parent:
   Node {
     type: 'AssignmentExpression',
     start: 5895,
     end: 5937,
     loc: SourceLocation { start: [Object], end: [Object] },
     range: [ 5895, 5937 ],
     operator: '=',
     left:
      Node {
        type: 'MemberExpression',
        start: 5895,
        end: 5915,
        loc: [Object],
        range: [Array],
        object: [Object],
        property: [Object],
        computed: false,
        leadingComments: null,
        _babelType: 'MemberExpression',
        parent: [Circular] },
     right: [Circular],
     leadingComments: null,
     _babelType: 'AssignmentExpression',
     parent:
      Node {
        type: 'ExpressionStatement',
        start: 5895,
        end: 5938,
        loc: [Object],
        range: [Array],
        expression: [Circular],
        leadingComments: [Array],
        trailingComments: [Array],
        _babelType: 'ExpressionStatement',
        parent: [Object] } } }
@SimenB
Copy link
Member

SimenB commented Nov 4, 2018

🎉 This issue has been resolved in version 21.27.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@SimenB SimenB added the released label Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants