Last active
November 2, 2016 22:24
-
-
Save ivawzh/94ebd97838a28f732afe768eadaa808f to your computer and use it in GitHub Desktop.
Javascript .reject in .catch will not be caught in the other .catch
This file contains hidden or 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
describe.only('catch of catch', () => { | |
it('does not catches error as expected', done => { | |
function errra () { | |
return new Promise((resolve, reject) => { | |
reject(3) | |
}) | |
} | |
Promise.resolve() | |
.then(() => { throw Error(123) }) | |
.catch(err => { | |
console.log(1111) | |
console.log(err) | |
errra() | |
}) | |
.then(() => { | |
console.log('should not be here') | |
}) | |
.catch(err2 => { | |
console.log(222) | |
console.log(err2) | |
expect(err2.message).to.eq(3) | |
done() | |
}) | |
}) | |
it('catches error', done => { | |
function errra () { | |
return new Promise((resolve, reject) => { | |
reject(new Error('new error')) | |
}) | |
} | |
Promise.resolve() | |
.then(() => { throw Error('original error') }) | |
.catch(err => { | |
return err | |
}) | |
.then(data => { | |
return errra() | |
}) | |
.catch(err2 => { | |
expect(err2.message).to.eq('new error') | |
done() | |
}) | |
}) | |
it('returns rejected error from catch', done => { | |
function errra () { | |
return new Promise((resolve, reject) => { | |
reject(new Error('new error')) | |
}) | |
} | |
Promise.resolve() | |
.then(() => { throw Error('original error') }) | |
.catch(err => { | |
return errra() | |
}) | |
.catch(err2 => { | |
expect(err2.message).to.eq('new error') | |
done() | |
}) | |
}) | |
}) | |
// ✗ npm t | |
// > [email protected] test /Users/ivan.wang/rea/proposals-esign-gateway | |
// > NODE_ENV=test node_modules/mocha/bin/mocha test/*_spec.js test/**/*_spec.js | |
// catch of catch | |
// 1111 | |
// [Error: 123] | |
// should not be here | |
// 1) does not catches error as expected | |
// ✓ catches error | |
// ✓ returns rejected error from catch | |
// 2 passing (2s) | |
// 1 failing | |
// 1) catch of catch does not catches error as expected: | |
// Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment