mardi 29 mars 2016

How to deal with chai spies `with` in recursion calls?

So if I want to check called.with() but testable function calls itself after the first call several times, how can I check if it calls itself correctly?

Example:

function checkMe (name, entity) {
  if (Array.isArray(entity)) {
    return entity.map(iteratee => checkMe(name, iteratee));
  }

  return output(name, entity);
}

function output (name, data) {
    return { name: name, data: data };
}

checkMe('match', [
    {
        prop: true,
        non: false
    },

    {
        prop: true,
        non: false
    },

    {
        prop: true,
        non: false
    }
]);

I would like to test it like this:

expect(checkMeSpy).to.have.been.called.with(
    ['match', { prop: true, non: false }],
    ['match', { prop: true, non: false }],
    ['match', { prop: true, non: false }]
);   

Aucun commentaire:

Enregistrer un commentaire