Skip to content

FR Rule: Prevent snapshot inside wait #214

Closed

Description

@SBoudrias

I wonder if there'd be a way to make sure there's no snapshot done inside wait conditions.

Example invalid usage:

await wait(() => {
  expect(foo).toMatchSnapshot();
});

Valid:

expect(foo).toMatchSnapshot();

This is between jest and and testing-library, but the depreciated wait() functions allow tests like this to be written and lead to flakey cases.

Activity

  1. Belco90 commented on Aug 17, 2020

    @Belco90
    Member

    Hey Simon, sorry for the late response!

    This sounds like an interesting rule, but I don't see the problem 100% clear. Could you elaborate more around the issues this can cause please? Thanks.

  2. SBoudrias commented on Aug 18, 2020

    @SBoudrias
    Author

    Yes of course!

    The problem is that wait() runs in a timer loop. So it'll retry every n amount of time.

    If there's a snapshot inside the wait condition, jest will generate one snapshot per loop.

    The problem then is the amount of loop ran until the condition is met will vary between different computers (or CI machines.) This leads to tests that will regenerate a lot of snapshots until the condition is match when devs run those tests locally updating the snapshots; e.g devs cannot run jest -u locally or it'll generate a lot of invalid snapshots who'll fail during CI.

    This would be fine if snapshots were generated manually; but auto-update causes conflicts.

  3. Belco90 commented on Aug 18, 2020

    @Belco90
    Member

    I see. Yeah, didn't think about the auto update. This can definitely be a nice rule, something like no-wait-snapshot. Are you interested into give it a try?

  4. added 6 commits that reference this issue on Aug 26, 2020
    f165987
    143d454
    7a51c71
    af9c8ee
    b903d3a
    f691293
  5. added a commit that references this issue on Aug 31, 2020
    7e2f5e3
  6. Belco90 commented on Aug 31, 2020

    @Belco90
    Member

    🎉 This issue has been resolved in version 3.8.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  7. added a commit that references this issue on Sep 20, 2020
    4b7300e
  8. github-actions commented on Mar 28, 2021

    @github-actions

    🎉 This issue has been resolved in version 4.0.0-beta.1 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

  9. added a commit that references this issue on Apr 11, 2021
    6e76a28
  10. github-actions commented on Apr 11, 2021

    @github-actions

    🎉 This issue has been resolved in version 4.0.0 🎉

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions