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

Allow regexp for interceptor specs. #347

Closed
jamestalmage opened this issue Jul 13, 2015 · 8 comments
Closed

Allow regexp for interceptor specs. #347

jamestalmage opened this issue Jul 13, 2015 · 8 comments

Comments

@jamestalmage
Copy link

Due to the high occurrence of / in paths, most people will probably use the string constructor form.

  scope.get(new Regexp("/somePath[a-z0-9]+")).reply(/** **/);
@sindresorhus
Copy link

👍 I think .get() should support both a regex and a function. This matches the filtering methods.

@ericsaboia
Copy link
Contributor

+1

@hyzhak
Copy link
Contributor

hyzhak commented Dec 21, 2015

👍 definitely it will be great to have function in scope.get that be able to generate body of reply based on parsed path.

Something like this:

scope.get(function(url) {
   if(match(url)) {
      return {
        code: 200,
        body: generateBody(url)
      };
   } else {
      //it does not handle url
      return null;
   }
});

or that way

scope
  .get(function(url) {
    return match(url);
  })
  .reply(function(url) {
     return generateBody(url);
  });

@stale
Copy link

stale bot commented Sep 17, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. We try to do our best, but nock is maintained by volunteers and there is only so much we can do at a time. Thank you for your contributions.

@mastermatt
Copy link
Member

Should this issue be open?
The features were added and still exist. tests

@RichardLitt
Copy link
Member

Looks like it works for me. @jamestalmage @sindresorhus does this match your needs?

@sindresorhus
Copy link

Yes, thanks. For context, it was added in c303122.

@RichardLitt
Copy link
Member

Awesome. Thanks for raising this, @mastermatt. All, this should be fixed now.

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

No branches or pull requests

7 participants