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

jest/no-test-callback => TypeError: Cannot read property 'type' of undefined #195

Closed
MickaelBergem opened this issue Nov 2, 2018 · 3 comments
Labels

Comments

@MickaelBergem
Copy link

MickaelBergem commented Nov 2, 2018

It looks like eslint crashes on a specific file in my project:

const request = require('supertest');

describe('eslintplugin-jest PoC', () => {
  test('should not crash', () => new Promise((done) => {
    request() // Some parts of the code not reproduced here but issue will happen with this simplified file
      .then(() => {
        expect(1).toBe(1);
        return done();
      });
  }));
});

Stacktrace:

$ /some/frontend_project/node_modules/.bin/eslint server/poc.js
TypeError: Cannot read property 'type' of undefined
    at isPromiseReturnedLater (/some/frontend_project/node_modules/eslint-plugin-jest/rules/valid-expect-in-promise.js:61:24)
    at isParentThenOrPromiseReturned (/some/frontend_project/node_modules/eslint-plugin-jest/rules/valid-expect-in-promise.js:92:5)
    at promiseCallbacks.some.promiseCallback (/some/frontend_project/node_modules/eslint-plugin-jest/rules/valid-expect-in-promise.js:107:10)
    at Array.some (<anonymous>)
    at verifyExpectWithReturn (/some/frontend_project/node_modules/eslint-plugin-jest/rules/valid-expect-in-promise.js:103:20)
    at MemberExpression (/some/frontend_project/node_modules/eslint-plugin-jest/rules/valid-expect-in-promise.js:154:13)
    at listeners.(anonymous function).forEach.listener (/some/frontend_project/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/some/frontend_project/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/some/frontend_project/node_modules/eslint/lib/util/node-event-generator.js:251:26)
error Command failed with exit code 2.

Versions

  • eslint@5.8.0
  • eslint-plugin-jest@21.26.2

Eslint config

yarn eslint --print-config server/poc.js produces:

[...]
    "jest/expect-expect": [
      "warn",
      {
        "assertFunctionNames": [
          "expect",
          "assert"
        ]
      }
    ],
    "jest/no-test-callback": "warn",
    "jest/no-test-return-statement": "warn",
    "jest/prefer-to-be-undefined": "warn",
    "jest/prefer-to-contain": "warn",
    "jest/valid-expect-in-promise": "warn",
[...]

I also extend plugin:jest/recommended and airbnb.

Everything works perfectly well for the other files.

Let me know if you need more information.

@MickaelBergem MickaelBergem changed the title TypeError: Cannot read property 'type' of undefined jest/no-test-callback` => TypeError: Cannot read property 'type' of undefined Nov 2, 2018
@MickaelBergem MickaelBergem changed the title jest/no-test-callback` => TypeError: Cannot read property 'type' of undefined jest/no-test-callback => TypeError: Cannot read property 'type' of undefined Nov 2, 2018
@SimenB
Copy link
Member

SimenB commented Nov 2, 2018

Would you like to send a PR with a fix? :)

lukeapage added a commit to lukeapage/eslint-plugin-jest that referenced this issue Nov 4, 2018
lukeapage added a commit to lukeapage/eslint-plugin-jest that referenced this issue Nov 4, 2018
@SimenB SimenB closed this as completed in 60919f6 Nov 6, 2018
@SimenB
Copy link
Member

SimenB commented Nov 6, 2018

🎉 This issue has been resolved in version 21.27.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@SimenB SimenB added the released label Nov 6, 2018
@MickaelBergem
Copy link
Author

Thank you @lukeapage and @SimenB :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants