Use case: when testing a code in Jest that already uses promises, I didn't want to use Promise resolve to peek into the promise, in order to not mess up the function execution.
My helper function:
function promiseValue(p) {
return process.binding('util').getPromiseDetails(p)[1];
}
Test for it with Jest:
test('promiseValue', () => {
expect(promiseValue(new Promise(()=>{}))).toEqual(undefined);
expect(promiseValue(Promise.resolve(2))).toEqual(2);
expect(promiseValue(Promise.reject(0))).toEqual(0);
})
No comments:
Post a Comment