1

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
  • 169,008
  • 28
  • 173
  • 236
PositiveGuy
  • 17,621
  • 26
  • 79
  • 138
  • 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) – SK. 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.
  • 35,491
  • 6
  • 51
  • 50
2

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

Hayk Mantashyan
  • 328
  • 2
  • 18
0
 gateway.data(undefined);

as undefined is not a string but a variable

manoj
  • 3,391
  • 2
  • 20
  • 30
0

Pick one:

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

About function arguments.

Vidul
  • 10,128
  • 2
  • 18
  • 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

SK.
  • 4,174
  • 4
  • 30
  • 48