From eefece4be619160d41e7b46c446cef63c26f7ff8 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Fri, 1 Nov 2019 16:05:02 -0700 Subject: [PATCH] Hide stack frames when they're empty Summary: In the next diff we'll introduce syntax errors, which we don't show stackframes for since they don't make sense. This diff removes the Stack Frame section when there are no stack frames available. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D18278831 fbshipit-source-id: 0a6ad5c3b7fed76123b6ad3ccfc8f3f0b044bda2 --- .../LogBox/UI/LogBoxInspectorStackFrames.js | 5 +++++ .../LogBoxInspectorStackFrames-test.js | 19 +++++++++++++++++++ .../LogBoxInspectorStackFrames-test.js.snap | 2 ++ 3 files changed, 26 insertions(+) diff --git a/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js b/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js index 12f674f10de..552ba9dfaf4 100644 --- a/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js +++ b/Libraries/LogBox/UI/LogBoxInspectorStackFrames.js @@ -54,6 +54,11 @@ function LogBoxInspectorStackFrames(props: Props): React.Node { return `Collapse ${collapsedCount} frames`; } } + + if (props.log.getAvailableStack().length === 0) { + return null; + } + return ( { it('should render stack frames with 1 frame collapsed', () => { const output = render.shallowRender( @@ -51,4 +62,12 @@ describe('LogBoxInspectorStackFrame', () => { expect(output).toMatchSnapshot(); }); + + it('should render null for empty stack frames', () => { + const output = render.shallowRender( + {}} log={logNoStackFrames} />, + ); + + expect(output).toMatchSnapshot(); + }); }); diff --git a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorStackFrames-test.js.snap b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorStackFrames-test.js.snap index 6796f92d8fe..a9b6036c9b3 100644 --- a/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorStackFrames-test.js.snap +++ b/Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorStackFrames-test.js.snap @@ -1,5 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`LogBoxInspectorStackFrame should render null for empty stack frames 1`] = `null`; + exports[`LogBoxInspectorStackFrame should render stack frames with 1 frame collapsed 1`] = `