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

.reply is not returning the Interceptor #1822

Closed
idangozlan opened this issue Nov 27, 2019 · 4 comments
Closed

.reply is not returning the Interceptor #1822

idangozlan opened this issue Nov 27, 2019 · 4 comments
Labels
support General questions or support.

Comments

@idangozlan
Copy link

idangozlan commented Nov 27, 2019

What is the expected behavior?

const scopeModel = nock('http://localhost')
          .get('/api/...')
          .reply(200, response);

scopeModel to be the Interceptor, so we can run nock.removeInterceptor(scopeModel);

What is the actual behavior?
reply() not returning the Interceptor, so nock.removeInterceptor(scopeModel); will not work

Possible solution
to return the Interceptor when using reply(), so we don't have to do it in 2 lines

Versions

Software Version(s)
Nock 11.7.0
@mastermatt
Copy link
Member

@idangozlan reply returns the Scope instance, which is the expected behavior.

To perform what you're attempting to do, you need to save a reference of the interceptor.

  const scopeModel = nock('http://localhost');
  const apiInterceptor = scopeModel.get('/api/...');

  apiInterceptor.reply(200, response);

  // ... do stuff
  
  nock.removeInterceptor(apiInterceptor);

docs

@mastermatt mastermatt added the support General questions or support. label Nov 27, 2019
@idangozlan
Copy link
Author

got it. thanks :)

@meelash
Copy link

meelash commented Dec 26, 2019

Is this mentioned or even alluded to with an example in the Readme? I swear I spent a long time looking exactly for this and couldn't find anything?

@mastermatt
Copy link
Member

Not in any clear way. This should be included in #1606

Alexsey added a commit to Alexsey/nock that referenced this issue Jul 1, 2020
The fact that `removeInterceptor` works on some chains and doesn't work on other chains is very confusing because it means that existing code may break while the behavior is getting only extended (opposit to modified). Also, because documentation is not giving a clear difference on what chain methods returns what type of values. There are a bunch of issues on it:
nock#1822
nock#1117
nock#600
Alexsey added a commit to Alexsey/nock that referenced this issue Jul 1, 2020
The fact that `removeInterceptor` works on some chains and doesn't work on other chains is very confusing because it means that existing code may break while the behavior is getting only extended (opposite to modified). Also, because documentation is not giving a clear difference on what chain methods returns what type of values. There are a bunch of issues on it:
nock#1822
nock#1117
nock#600
Alexsey added a commit to Alexsey/nock that referenced this issue Oct 3, 2020
The fact that `removeInterceptor` works on some chains and doesn't work on other chains is very confusing because it means that existing code may break while the behavior is getting only extended (opposite to modified). Also, because documentation is not giving a clear difference on what chain methods returns what type of values. There are a bunch of issues on it:
nock#1822
nock#1117
nock#600
Alexsey added a commit to Alexsey/nock that referenced this issue Oct 3, 2020
The fact that `removeInterceptor` works on some chains and doesn't work on other chains is very confusing because it means that existing code may break while the behavior is getting only extended (opposite to modified). Also, because documentation is not giving a clear difference on what chain methods returns what type of values. There are a bunch of issues on it:
nock#1822
nock#1117
nock#600
Alexsey added a commit to Alexsey/nock that referenced this issue Oct 3, 2020
The fact that `removeInterceptor` works on some chains and doesn't work on other chains is very confusing because it means that existing code may break while the behavior is getting only extended (opposite to modified). Also, because documentation is not giving a clear difference on what chain methods returns what type of values. There are a bunch of issues on it:
nock#1822
nock#1117
nock#600
gr2m pushed a commit that referenced this issue Nov 7, 2021
The fact that `removeInterceptor` works on some chains and doesn't work on other chains is very confusing because it means that existing code may break while the behavior is getting only extended (opposite to modified). Also, because documentation is not giving a clear difference on what chain methods returns what type of values. There are a bunch of issues on it:
#1822
#1117
#600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support General questions or support.
Projects
None yet
Development

No branches or pull requests

3 participants