Skip to content

Automatically cleanup if afterEach is detected  #77

Closed
@afontcu

Description

@afontcu

Right now, users need to call afterEach(cleanup) or configure Jest to do so. This makes sure test run in isolation, but requires manual action.


As React Testing Library just did, we should probably automatically call cleanup if afterEach method exists.

RTL ended up offering two opt-out mechanisms (via custom import or using an env variable), but I'm not sure this is totally needed. I would keep the env variable (VTL_SKIP_AUTO_CLEANUP), but still have a single import point (instead of creating that "pure" version on VTL). Not a big deal, though.

So a PR (or several PRs) should:

  • Automatically call afterEach(cleanup) if afterEach exists.
  • Add an opt-out mechanism by using VTL_SKIP_AUTO_CLEANUP.
  • Add tests asserting the behavior outlined above.
  • Remove cleanup references from tests and docs.
  • Replace cleanup-after-each with a warning (reference).
  • State that the change is a breaking change (so that we take it into account when merging!).

After that, we'd need to update the official docs.

I'm marking this as a good first issue since details are outlined and the referenced PR from RTL makes a great starting point :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgood first issueGood for newcomershas PRThere's an open PR to solve/close the issuereleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions