mardi 20 février 2018

Test Double testing default arguments

I am using testdouble to test my code.

It is working amazing, except for testing default arguments. The reason for this is it does not seem to be calling my functions default arguments in the mocked function.

Here is an example:

const add = (a = 1,b = 1) => a + b

//td is a global variable
test(t => {
    const addSpy = td.func(add);
    addSpy();
    td.verify(addSpy(1,1), {times: 1})
})

In this case, the verify function says my function is invoked with no arguments.

I understand that it didn't call the original function, but was under the impression it would mock the default parameters in the spy (therefore calling with 2 parameters by default).

Thus, I am left confused as how to test that my default parameters are set. Does anyone have any ideas?

Aucun commentaire:

Enregistrer un commentaire