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

Lint for setting advanceTimers with user-event when using jest.useFakeTimers #979

Open
backwardok opened this issue Dec 30, 2024 · 0 comments
Labels
new rule New rule to be included in the plugin triage Pending to be triaged by a maintainer

Comments

@backwardok
Copy link

Name for new rule

advance-timers-with-fake-timers

Description of the new rule

Enforce using the advanceTimers option for user-event when using jest's useFakeTimers in order to prevent testing timeouts

Testing Library feature

user-event's advanceTimers option when using fake timers

Testing Library framework(s)

user-event (across any Testing Library framework that can use it)

What category of rule is this?

Warns about a potential error

Optional: other category of rule

No response

Code examples

Using fake timers within a test directly:

jest.useFakeTimers();
const user = userEvent.setup(); // Warn - advanceTimers not set
beforeEach(() => {
  jest.useFakeTimers()
});

test('some behavior with user action', async () => {
  const user = userEvent.setup(); // Warn - advanceTimers not set
  // Test behavior
})

Anything else?

No response

Do you want to submit a pull request to make the new rule?

No

@backwardok backwardok added new rule New rule to be included in the plugin triage Pending to be triaged by a maintainer labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new rule New rule to be included in the plugin triage Pending to be triaged by a maintainer
Projects
None yet
Development

No branches or pull requests

1 participant