Friday, 28 April 2017

Sinon: force callback call

I'm testing a function with this code:

return new Promise((ok, fail) => {
        this.repository.findById(id, (error, result) => {
            if (error)
                return fail(error);
            ok(result);
        });
    });

I want to test the path of the fail, i.e., when the findById method calls the callback with an error. I'm using sinon to generate a stub for my repository and its findById method, but I don't know how to force the stub to call the callback with the desired parameters

Anybody did something like that before?

Thanks



via Jose Selesan

No comments:

Post a Comment