From 7af78282f116d5aaacc589f6868087b496457aba Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 21 Nov 2018 18:19:00 +0000 Subject: [PATCH] Add test verifying nested lazy is unsupported --- .../src/__tests__/ReactLazy-test.internal.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js b/packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js index 9296c06646..c657b57c49 100644 --- a/packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactLazy-test.internal.js @@ -512,6 +512,36 @@ describe('ReactLazy', () => { expect(root).toMatchRenderedOutput('Friends Bye'); }); + it('throws with a useful error when wrapping lazy() multiple times', async () => { + const Lazy1 = lazy(() => fakeImport(Text)); + const Lazy2 = lazy(() => fakeImport(Lazy1)); + + const root = ReactTestRenderer.create( + }> + + , + { + unstable_isConcurrent: true, + }, + ); + + expect(root).toFlushAndYield(['Loading...']); + expect(root).toMatchRenderedOutput(null); + + await Promise.resolve(); + root.update( + }> + + , + ); + expect(() => { + root.unstable_flushAll(); + }).toThrow( + 'Element type is invalid. Received a promise that resolves to: [object Object]. ' + + 'Promise elements must resolve to a class or function.', + ); + }); + it('warns about defining propTypes on the outer wrapper', () => { const LazyText = lazy(() => fakeImport(Text)); expect(() => {