Skip to content

Crashes when expect with no following statement. #357

@garyking

Description

@garyking

If you have code like expect() without anything after, like toBe, then it crashes the linter. It shouldn't crash the linter. I imagine Jest would do enough to notify you that something is wrong, or at least the linter should indicate that the following statement is missing.

Sample code:

test('test', () => {
  expect('a');
})

Which results in the following error when linting:

TypeError: Cannot read property 'name' of undefined
Occurred while linting asdf.test.js:2
    at methodName (/usr/local/lib/node_modules/eslint-plugin-jest/lib/rules/util.js:66:40)
    at expectToBeCase (/usr/local/lib/node_modules/eslint-plugin-jest/lib/rules/util.js:42:140)
    at CallExpression (/usr/local/lib/node_modules/eslint-plugin-jest/lib/rules/prefer-to-be-null.js:25:45)
    at listeners.(anonymous function).forEach.listener (/usr/local/lib/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/usr/local/lib/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/usr/local/lib/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/usr/local/lib/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/usr/local/lib/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (/usr/local/lib/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions