default parameter for `method`
See original GitHub issueNotes
I do know that specific helper functions exist for the various HTTP verbs, however, for our specific use case, we had to use the .intercept()
method. I can gladly share a quick PR for this.
What is the expected behavior?
When nock( host ).intercept( ... )
is invoked without a method as the second argument, it should automatically assume the GET
verb or, if that is done for a reason, an error should be thrown.
What is the actual behavior?
On this line, when method.toUpperCase()
is called and if method
is null or undefined, the application using nock
crashes.
Possible solution A pretty simple way to fix it in case a error should be thrown:
if ( typeof method === 'undefined' || !method ) {
throw new Error( 'The "method" parameter is a required argument for the .intercept() function.' );
}
For defaults: method = ( method && method.toUpperCase() ) || 'GET';
should do the trick.
How to reproduce the issue
Runkit: nock-intercept-issue-1265
Having problem producing a test case? Try and ask the community for help. If the test case cannot be reproduced, the Nock community might not be able to help you.
Does the bug have a test case? No.
Versions
Software | Version(s) |
---|---|
Nock | 10.0.3 |
Node | 11.2.0 |
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (3 by maintainers)
@gr2m, oh, alright!
And yes, on it! 👍
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!