question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

default parameter for `method`

See original GitHub issue

Notes 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:closed
  • Created 5 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
labsvisualcommented, Dec 7, 2018

@gr2m, oh, alright!

And yes, on it! 👍

0reactions
lock[bot]commented, Dec 22, 2018

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >
Does Java support default parameter values? - Stack Overflow
No, the structure you found is how Java handles it, (that is, with overloading instead of default parameters).
Read more >
C# Default Parameter Value - W3Schools
A parameter with a default value, is often known as an "optional parameter". From the example above, country is an optional parameter and...
Read more >
Default arguments - cppreference.com
For non-template functions, default arguments can be added to a function that was already declared if the function is redeclared in the same...
Read more >
Java Default Parameters Using Method Overloading | Baeldung
Learn how to use method overloading to simulate default parameters in Java.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found