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

feat: add ability to mock requests in record mode #2457

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

markgmilner
Copy link

Related issues:

Description

Adds a new allow_mocked recorder option.

If true, the recorder will only record unmatched requests. Calls to matched requests will return the mocked response and will not be recorded.

This is useful when you want your tests to use specific responses for certain requests but to record the rest.

@HartS
Copy link

HartS commented Apr 22, 2023

This sounds useful! Looking forward to it

@sdotson
Copy link

sdotson commented Jul 27, 2023

what needs to happen for this to get reviewed/merged?

My use case: Make it a lot more visible to engineers that un-mocked network requests are happening, even in files that have some mocked requests already. The goal would be to get that number down to zero in unit tests.

@irfan798
Copy link

The problem with this is its using matchOrigin which doesnt check body beforehand. It assumes that there is a mock but then throws an error when it can't match body later.

So it mistakenly forwards to mocked request instead of sending it to internet and recording it.

https://github.com/ava-labs/nock/blob/allow_mocked/lib/recorder.js#L246

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

Successfully merging this pull request may close these issues.

None yet

4 participants