diff --git a/src/promise.js b/src/promise.js index 3bef942..362bb23 100644 --- a/src/promise.js +++ b/src/promise.js @@ -307,6 +307,11 @@ export class ZalgoPromise { return Promise.resolve(this); // eslint-disable-line compat/compat } + lazy() : ZalgoPromise { + this.errorHandled = true; + return this; + } + static resolve(value : ZalgoPromise | Y) : ZalgoPromise { if (value instanceof ZalgoPromise) { diff --git a/test/tests/reject.js b/test/tests/reject.js index 3c7c086..0115c31 100644 --- a/test/tests/reject.js +++ b/test/tests/reject.js @@ -512,4 +512,26 @@ describe('reject cases', () => { }, 100); }, 100); }); + + it('should not call unhandled promise method when lazy promise is rejected without having a handler', () => { + + window.addEventListener('error', () => { + // pass + }); + + let error; + + const listener = ZalgoPromise.onPossiblyUnhandledException(err => { + error = err; + }); + + ZalgoPromise.reject(new Error('foobar')).lazy(); + + return ZalgoPromise.delay(50).then(() => { + listener.cancel(); + if (error) { + throw new Error(`Expected error to not be thrown`); + } + }); + }); });