Skip to content

feat: support clearAllMocks / resetAllMocks / restoreAllMocks #136

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

Merged
merged 4 commits into from
Apr 25, 2025

Conversation

9aoy
Copy link
Contributor

@9aoy 9aoy commented Apr 25, 2025

Summary

  • clearAllMocks: Calls .mockClear() on all spies.
  • resetAllMocks: Calls .mockReset() on all spies.
  • restoreAllMocks: Calls .mockRestore() on all spies.
describe('clearAllMocks', () => {
  const sayHi = rstest.fn();

  afterEach(() => {
    rstest.clearAllMocks();
  });

  it('spy', () => {
    sayHi.mockImplementation(() => 'hi');

    expect(sayHi('bob')).toBe('hi');

    expect(sayHi).toHaveBeenCalledTimes(1);
  });

  it('spy - 1', () => {
    sayHi.mockImplementation(() => 'hello');

    expect(sayHi('bob')).toBe('hello');

    expect(sayHi).toHaveBeenCalledTimes(1);
  });
});

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@9aoy 9aoy merged commit fffcc23 into main Apr 25, 2025
11 checks passed
@9aoy 9aoy deleted the feat/clearAllMocks branch April 25, 2025 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant