Skip to content

feat: support mock withImplementation #128

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 2 commits into from
Apr 24, 2025
Merged

feat: support mock withImplementation #128

merged 2 commits into from
Apr 24, 2025

Conversation

9aoy
Copy link
Contributor

@9aoy 9aoy commented Apr 23, 2025

Summary

  • withImplementation: Accepts a function which should be temporarily used as the implementation of the mock while the callback is being executed.
test('test', () => {
  const mock = rstest.fn(() => 'outside callback');

  mock.withImplementation(
    () => 'inside callback',
    () => {
      mock(); // 'inside callback'
    },
  );

  mock(); // 'outside callback'
});

Related Links

Checklist

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

@9aoy 9aoy merged commit dad894b into main Apr 24, 2025
10 checks passed
@9aoy 9aoy deleted the withImplementation branch April 24, 2025 03:17
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