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

Mock history #4025

Open
blephy opened this issue Jan 23, 2025 · 4 comments · May be fixed by #4029
Open

Mock history #4025

blephy opened this issue Jan 23, 2025 · 4 comments · May be fixed by #4029
Labels
enhancement New feature or request

Comments

@blephy
Copy link

blephy commented Jan 23, 2025

This would solve...

When intercepting http call with MockAgent, we are not able to assert provided request configuration (body, querystring, headers etc...)

The implementation should look like...

fetch-mock can permit it this way :

beforeEach(() => {
 mockClient.resetHistory();
})

it('should ...', async () => {
 mockClient.intercept({
  path: '...',
  method: 'POST'
 })
 .reply(201, 'hello)
 .time(1)

 await fetch('...', {
  body: JSON.stringify({ value: 'hello' });
 })

 expect(mockClient.history.getCall(1).body).toMatchSnapshot()
})
@blephy blephy added the enhancement New feature or request label Jan 23, 2025
@metcoder95
Copy link
Member

That can be a good addition to the MockScope indeed; would you like to send a PR for that?

@blephy
Copy link
Author

blephy commented Jan 24, 2025

It would be nice yeah :)

I will work on this ty

@blephy
Copy link
Author

blephy commented Jan 25, 2025

Hello @metcoder95

I cannot push my PR.

I have finished a first implementation which may satisfies a lot of usage. This is tested but there is some tests to write again.

Can you let me push to be able to discuss around my code in a PR ?

@metcoder95
Copy link
Member

Please, make a fork of the repository to your GH account and you can create a PR from the branch in your fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants