0

What is the proper way to send undefined as the value here in my test:

 it('returns response with no content status for no data found', function (done) {
        gateway.data('undefined');
        ...rest of code
        done();
    });

or should I do gateway.data(undefined); or gateway.data("undefined");

purpose is I'm setting it to defined on purpose because my test needs to test that case in the calling function.

here's the gateway.data function:

module.exports = {
    data: function(someData){
        globalData = someData;
    },
    findAll: function(){
        return globalData;
    }
};
mplungjan
  • 155,085
  • 27
  • 166
  • 222
PositiveGuy
  • 14,005
  • 18
  • 67
  • 121
  • 1
    you can just omit it entirely. – Daniel A. White Jul 24 '15 at 19:09
  • 1
    If you don't pass a value, the parameters are set to `undefined` implicitly. However, if you are working with `arguments`, then there is a big difference between `foo(undefined)` and `foo()`. – Felix Kling Jul 24 '15 at 19:12
  • possible duplicate of [How to pass the value 'undefined' to a function with multiple parameters?](http://stackoverflow.com/questions/8998612/how-to-pass-the-value-undefined-to-a-function-with-multiple-parameters) – Simpal Kumar Jul 24 '15 at 19:26

6 Answers6

2

You should go with gateway.data(undefined); as the others are passing a string and not undefined.

Rob M.
  • 33,381
  • 6
  • 50
  • 46
2

The best way is to call gateway.data(); someData will be undefined in this case

Hayk Mantashyan
  • 318
  • 2
  • 17
0
 gateway.data(undefined);

as undefined is not a string but a variable

manoj
  • 2,833
  • 1
  • 18
  • 28
0

Pick one:

gateway.data(undefined);
gateway.data(void 0);
gateway.data();
Sebastian Nette
  • 6,536
  • 2
  • 16
  • 17
0
gateway.data(); // implicitly: someData becomes undefined

About function arguments.

Vidul
  • 9,616
  • 2
  • 17
  • 20
0

gateway.data(undefined); this way should work, what is the problem?

Also, the void operator seems to be the most common way to explicitly get undefined.

See here

Simpal Kumar
  • 3,765
  • 3
  • 26
  • 48