Skip to content

[prefer-explicit-assert] Incomplete expect statement causes TypeError #475

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

Closed
DaJoTo opened this issue Sep 16, 2021 · 5 comments · Fixed by #476
Closed

[prefer-explicit-assert] Incomplete expect statement causes TypeError #475

DaJoTo opened this issue Sep 16, 2021 · 5 comments · Fixed by #476
Assignees
Labels
bug Something isn't working released

Comments

@DaJoTo
Copy link

DaJoTo commented Sep 16, 2021

Plugin version

4.12.2

ESLint version

7.32.0

Node.js version

15.11.0

npm/yarn version

yarn 1.22.10

Operating system

macOS Big Sur, version 11.6

Bug description

Leaving an incomplete expect statement with the prefer-explict-assert rule active breaks the linter.

Steps to reproduce

  • configure the prefer-explicit-assert rule to be active
  • write a basic test which includes expect('something');
  • see that the linter fails with a TypeError

Error output/screenshots

Oops! Something went wrong! :(                                                                                   
                                                                                                                         
ESLint: 7.32.0                                                                                                           
                                                                                                                         
TypeError: Cannot read property 'name' of undefined
Occurred while linting [...]/components/OverrideSummary.test.tsx:1
    at [...]/node_modules/eslint-plugin-testing-library/rules/prefer-explicit-assert.js:124:48
    at Array.forEach (<anonymous>)
    at Object.Program:exit ([...]/node_modules/eslint-pluging-testing-library/rules/prefer-explicit-assert.js:105:31)
    at enhancedRuleInstructions.<computed> ([...]/node_modules/eslint-plugin-testing-library/create-testing-library-rule/detect-testing-library-utils.js:518:105)
    at [...]/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit ([...]/node_modules/eslint/lib/linter/safe-emitter.js:45:38)                                                          
    at NodeEventGenerator.applySelector ([...]/node_modules/eslint/lib/linter/node-event-generator.js:293:26)
    at NodeEventGenerator.applySelectors ([...]/node_modules/eslint/lib/linter/node-event-generator.js:322:22)
    at NodeEventGenerator.leaveNode ([...]/node_modules/eslint/lib/linter/node-event-generator.js:345:14)
error Command failed with exit code 2.

ESLint configuration

module.exports = {
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint', 'jsx-a11y', 'no-only-tests'],
  extends: [
    'react-app',
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:jsx-a11y/recommended',
    'plugin:prettier/recommended',
    'prettier/@typescript-eslint',
    'prettier/react',
  ],
  parserOptions: {
    ecmaVersion: 6,
    project: ['./tsconfig.json', './cypress/tsconfig.json'],
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
    },
  },
  settings: {
    react: {
      version: 'detect',
    },
  },
  rules: {
    '@typescript-eslint/explicit-module-boundary-types': 0,
    'require-await': 0,
    '@typescript-eslint/no-inferrable-types': 1,
  },
  overrides: [
    {
      files: ['cypress/**/*.ts'],
      extends: ['plugin:cypress/recommended'],
      rules: {
        'cypress/no-unnecessary-waiting': 'warn',
      },
    },
    {
      files: ['*.test.ts', '*.test.tsx'],
      extends: ['plugin:testing-library/react', 'plugin:jest-dom/recommended'],
      rules: {
        'no-console': 'off',
        'testing-library/no-debug': 'warn',
        'testing-library/prefer-explicit-assert': ['error', { assertion: 'toBeInTheDocument' }],
        'testing-library/render-result-naming-convention': 'warn',
      },
    },
  ],
};

Rule(s) affected

prefer-explicit-assert

Anything else?

No response

Do you want to submit a pull request to fix this bug?

Yes, but need help

@DaJoTo DaJoTo added the bug Something isn't working label Sep 16, 2021
@MichaelDeBoey MichaelDeBoey changed the title Incomplete expect statement breaks causes TypeError [prefer-explicit-assert] Incomplete expect statement breaks causes TypeError Sep 16, 2021
@DaJoTo DaJoTo changed the title [prefer-explicit-assert] Incomplete expect statement breaks causes TypeError [prefer-explicit-assert] Incomplete expect statement causes TypeError Sep 16, 2021
@Belco90
Copy link
Member

Belco90 commented Sep 17, 2021

Hey @DaJoTo thanks for reporting this issue! Should be an easy one to fix, I think I can take a look during the weekend.

@github-actions
Copy link

🎉 This issue has been resolved in version 4.12.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Belco90
Copy link
Member

Belco90 commented Sep 20, 2021

@all-contributors please add @DaJoTo for bug

@allcontributors
Copy link
Contributor

@Belco90

I've put up a pull request to add @DaJoTo! 🎉

@DaJoTo
Copy link
Author

DaJoTo commented Sep 20, 2021

@Belco90 awesome that you got that patched so quickly. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants