Created
March 4, 2020 12:47
-
-
Save Nautigsam/94cba19dcb7f7ad806c87cb410077b94 to your computer and use it in GitHub Desktop.
Use case where it could be useful to explicit how to handle an error thrown with a Sinon stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const o = { | |
edit(cb) { | |
console.log('EDIT') | |
return Promise.resolve(false) | |
.then(cb) | |
} | |
} | |
function run() { | |
console.log('RUN') | |
return o.edit(fail => { | |
console.log('EDIT-CB') | |
if (fail) { | |
throw new Error('AAA') | |
} | |
}).catch(e => { | |
console.log('CATCH') | |
console.error(e) | |
}) | |
} | |
const sinon = require('sinon') | |
const s = sinon.stub(o, 'edit').yields(true).resolves() | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here I want to stub
o.edit
function and ensure that if an error is thrown, it is properly caught by thecatch
block.