mercredi 23 mai 2018

Simple Sinon test for returned value

How would one test the return value of a function?

For example, wanting to test that passing 2 integers to a function that adds them together, will return the correct answer...

index.js

...
function addNumbers(x, y) {
    return x + y;
}
...

index.test.js

it('Should return 5 when passed 3 and 2, done => {
    let stub = sinon.stub(index, 'addNumbers');

    // This is where I get stuck...
    stub.<SOMETHING GOES HERE>.should.equal(5);
})

Aucun commentaire:

Enregistrer un commentaire