question title
how to test promise? with mocha/chai and sinon
problem description
suppose you encapsulate a function that initiates an asynchronous request task, succeeds in executing onSuccess, and fails to execute onError. At the same time, in order to prevent asynchronous tasks from relying on the external environment, use sinon to do Substitute. Does this situation require writing test code, and if so, how?
related codes
//
// onSuccessonError
module.exports = function (onSuccess, onError) {
var p = new Promise(function (resolve, reject) {
setTimeout(function () {
resolve("ok")
}, 1000)
})
p.then(function (response) {
onSuccess(response)
}).catch(function (error) {
onError(error)
})
}