Skip to content

[max-expects] does not reset counter with fakeAsync in angular #1516

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
parloti opened this issue Feb 25, 2024 · 3 comments · Fixed by #1550
Closed

[max-expects] does not reset counter with fakeAsync in angular #1516

parloti opened this issue Feb 25, 2024 · 3 comments · Fixed by #1550

Comments

@parloti
Copy link

parloti commented Feb 25, 2024

max-expect does not reset the 'expect' counter when the callback is involved by fakeAsync.

describe('given decimal places', () => {
  it("test 1", fakeAsync(() => {
    expect(true).toBeTrue();
    expect(true).toBeTrue();
    expect(true).toBeTrue();
  }))

  it("test 2", fakeAsync(() => {
    expect(true).toBeTrue();
    expect(true).toBeTrue();
    expect(true).toBeTrue(); // => Too many assertion calls (6) - maximum allowed is 5 jest/max-expects
  }))
})
@G-Rath
Copy link
Collaborator

G-Rath commented Feb 25, 2024

There might be a somewhat coincidental bug here but ultimately you're expecting that the plugin understands the relationship between the parameter you're passing and what gets returned, which generally is not possible.

I'll have a look over the code to double check what's actually happening but it's very possible this will be a "won't fix"

@parloti
Copy link
Author

parloti commented Feb 25, 2024

Adding this:

if (jestFnCall?.type === 'test') {
  count = 0;
}

here:
https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/max-expects.ts#L56

Fixes it and all tests pass.

@G-Rath G-Rath changed the title [max-expect] does not reset counter with fakeAsync in angular [max-expects] does not reset counter with fakeAsync in angular Feb 25, 2024
Copy link

github-actions bot commented Apr 6, 2024

🎉 This issue has been resolved in version 28.1.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants