diff --git a/test/lazy.test.js b/test/lazy.test.js index fdafce1..46e9843 100644 --- a/test/lazy.test.js +++ b/test/lazy.test.js @@ -10,7 +10,7 @@ const React = require('react'), {Suspense} = React; // Imports -const {itRenders, lazy, removeSpacing} = require('./utils'); +const {itRenders, lazy, removeSpacing, preventUnhandledRejection} = require('./utils'); // Globals const spy = jest.fn; @@ -345,6 +345,7 @@ describe('multiple lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); expect(Lazy1).toHaveBeenCalled(); expect(Lazy2).toHaveBeenCalled(); expect(Lazy3).toHaveBeenCalled(); @@ -375,6 +376,7 @@ describe('multiple lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); expect(Lazy1).toHaveBeenCalled(); expect(Lazy2).toHaveBeenCalled(); expect(Lazy3).toHaveBeenCalled(); @@ -499,6 +501,7 @@ describe('multiple lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); expect(Lazy1.promise.abort).toHaveBeenCalledTimes(1); expect(Lazy2.promise.abort).toHaveBeenCalledTimes(1); @@ -543,6 +546,7 @@ describe('multiple lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); expect(Lazy1).toHaveBeenCalled(); expect(Lazy2).toHaveBeenCalled(); @@ -584,6 +588,7 @@ describe('multiple lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); expect(Lazy1.promise.abort).toHaveBeenCalledTimes(1); expect(Lazy2.promise.abort).toHaveBeenCalledTimes(1); @@ -647,6 +652,7 @@ describe('nested lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); await Lazy.promise; await expect(p).rejects.toBe(LazyInner.promise); }); @@ -669,6 +675,7 @@ describe('nested lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); await Lazy.promise; await LazyInner.promise; await expect(p).rejects.toBe(LazyInnerInner.promise); @@ -751,6 +758,7 @@ describe('nested lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); await Lazy3.promise; @@ -780,6 +788,7 @@ describe('nested lazy components', () => { ); const p = render(e); + preventUnhandledRejection(p); await Lazy1.promise; await Lazy2.promise; diff --git a/test/utils.js b/test/utils.js index d037d8b..ba782b9 100644 --- a/test/utils.js +++ b/test/utils.js @@ -12,6 +12,7 @@ const React = require('react'), // Throw any unhandled promise rejections process.on('unhandledRejection', err => { + console.log('Unhandled rejection'); // eslint-disable-line no-console throw err; }); @@ -20,7 +21,8 @@ module.exports = { itRenders: wrapMethod(itRenders), itRendersWithSyncCompare: wrapMethod(itRendersWithSyncCompare), lazy, - removeSpacing + removeSpacing, + preventUnhandledRejection }; /* @@ -195,3 +197,7 @@ function lazySync(component) { function removeSpacing(text) { return text.replace(/\s*(?:\r?\n|^|$)\s*/g, ''); } + +function preventUnhandledRejection(promise) { + promise.catch(() => {}); +}