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-snapshot-hint] is it supposed to warn on multiple snapshots in a different test but the same describe block? #1074

Closed
lostfictions opened this issue Mar 30, 2022 · 2 comments · Fixed by #1078

Comments

@lostfictions
Copy link

lostfictions commented Mar 30, 2022

Hey there, thanks for your quick work fixing #1068! Unfortunately, I'm still seeing an issue with prefer-snapshot-hint.

With "jest/prefer-snapshot-hint": ["warn", "multi"] set, this works fine:

describe("my cool test", () => {
  it("requires hints for a test with multiple snapshots", () => {
    expect(1).toMatchSnapshot("a cool hint");
    expect(2).toMatchSnapshot("another cool hint");
  });
});

This also works fine:

describe("my cool test", () => {
  it("doesn't require hints for a test with a single snapshot", () => {
    expect(2).toMatchSnapshot();
  });
});

However, this yields a warning:

describe("my cool test", () => {
  it("doesn't require hints for a test with a single snapshot", () => {
    expect(2).toMatchSnapshot();
    //        ^ Warning: You should provide a hint for this snapshot
  });

  it("requires hints for a test with multiple snapshots", () => {
    expect(1).toMatchSnapshot("a cool hint");
    expect(2).toMatchSnapshot("another cool hint");
  });
});

I see in the rule description there's a parenthetical "(meaning it includes nested calls)" -- is this what that means? The behaviour is a bit surprising to me -- I thought "nested calls" meant it would treat the scope as including all functions called from within an it() block, not all it() blocks within a describe() block.

@G-Rath
Copy link
Collaborator

G-Rath commented Mar 30, 2022

Yup that's another bug - your thinking on what "nested calls" means is correct - the behaviour shouldn't change just because it gets wrapped in a describe like that.

@github-actions
Copy link

github-actions bot commented Apr 8, 2022

🎉 This issue has been resolved in version 26.1.4 🎉

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
2 participants