You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When interceptor is added - it's added at the end of the list. I'd like to have opportunity to add interceptor at the beginning of the list so it'll be checked before existing.
Context:
When I write integration tests I have global mock for all third party calls that can potentially happen - it helps me forget about any potential call that can happen when I write my test scenraio. For example I'm covering some GET /something request with tests: this endpoint sends another call to third party that I already have mocked globally. In this particular test scenario I don't care about this call so I just want third party response to me with something that not an error to proceed with scenario I care about. And this is how I write tests for 95% of test scenarios.
Here's how this global mock looks like
constUUID_REGEXP=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/;Nock(BASE_URL).persist().get(newRegExp(`/v1/something/${UUID_REGEXP.source}`)).reply(200,()=>{constid='uuid_v4';return{ id };});
As you can see interceptor above catches any potential request to /v1/something/{id} so if for particular scenario I want to add another interceptor for a specific ID - I can't cause the global interceptor has regexp that catches everything. So what I'm doing is
Removing existing interceptor
Adding interceptor to catch request with my specific ID I need
Setting global interceptor back at the end of test
If there would be opportunity to add interceptor at the beginning of list for a specific ID - I would not need to remove my global interceptor! The interceptor for a specific ID would be check request at first, and if ID doesn't match - the request would checked by second interceptor (which is with RegExp to catch any ID) and mock it.
From the interface how to do it: I don't care being honest, for example it can be
Nock(BASE_URL).persist().get(`/v1/something/1`),{unshift: true})// specific flag to add to the beginnig of list.reply(200,{id: 1});
Alternatives
No response
If the feature request is accepted, would you be willing to submit a PR?
yes
The text was updated successfully, but these errors were encountered:
Please avoid duplicates
Context
When interceptor is added - it's added at the end of the list. I'd like to have opportunity to add interceptor at the beginning of the list so it'll be checked before existing.
Context:
When I write integration tests I have global mock for all third party calls that can potentially happen - it helps me forget about any potential call that can happen when I write my test scenraio. For example I'm covering some
GET /something
request with tests: this endpoint sends another call to third party that I already have mocked globally. In this particular test scenario I don't care about this call so I just want third party response to me with something that not an error to proceed with scenario I care about. And this is how I write tests for 95% of test scenarios.Here's how this global mock looks like
As you can see interceptor above catches any potential request to
/v1/something/{id}
so if for particular scenario I want to add another interceptor for a specific ID - I can't cause the global interceptor has regexp that catches everything. So what I'm doing isIf there would be opportunity to add interceptor at the beginning of list for a specific ID - I would not need to remove my global interceptor! The interceptor for a specific ID would be check request at first, and if ID doesn't match - the request would checked by second interceptor (which is with RegExp to catch any ID) and mock it.
From the interface how to do it: I don't care being honest, for example it can be
Alternatives
No response
If the feature request is accepted, would you be willing to submit a PR?
The text was updated successfully, but these errors were encountered: