@@ -4,6 +4,22 @@ import { Text, View } from 'react-native';
44import { render , screen } from '..' ;
55import { _console , logger } from '../helpers/logger' ;
66
7+ function MaybeSuspend ( {
8+ children,
9+ promise,
10+ suspend,
11+ } : {
12+ children : React . ReactNode ;
13+ promise : Promise < unknown > ;
14+ suspend : boolean ;
15+ } ) {
16+ if ( suspend ) {
17+ React . use ( promise ) ;
18+ }
19+
20+ return children ;
21+ }
22+
723test ( 'renders a simple component' , async ( ) => {
824 const TestComponent = ( ) => (
925 < View testID = "container" >
@@ -33,6 +49,15 @@ test('does not warn when no options are passed', async () => {
3349 expect ( _console . warn ) . not . toHaveBeenCalled ( ) ;
3450} ) ;
3551
52+ test ( 'supports null options' , async ( ) => {
53+ const TestComponent = ( ) => < Text testID = "test" > Test</ Text > ;
54+
55+ await render ( < TestComponent /> , null as any ) ;
56+
57+ expect ( screen . getByTestId ( 'test' ) ) . toBeOnTheScreen ( ) ;
58+ expect ( _console . warn ) . not . toHaveBeenCalled ( ) ;
59+ } ) ;
60+
3661test ( 'does not warn when only valid options are passed' , async ( ) => {
3762 const TestComponent = ( ) => < Text testID = "test" > Test</ Text > ;
3863 const Wrapper = ( { children } : { children : React . ReactNode } ) => < View > { children } </ View > ;
@@ -68,6 +93,64 @@ describe('render options', () => {
6893 } ) ;
6994} ) ;
7095
96+ describe ( 'hidden instance props' , ( ) => {
97+ test ( 'sets hidden suspended elements with no style to display none' , async ( ) => {
98+ const promise = new Promise < unknown > ( ( ) => { } ) ;
99+
100+ function TestComponent ( { suspend } : { suspend : boolean } ) {
101+ return (
102+ < React . Suspense fallback = { < Text > Loading...</ Text > } >
103+ < MaybeSuspend promise = { promise } suspend = { suspend } >
104+ < View testID = "hidden-target" >
105+ < Text > Ready</ Text >
106+ </ View >
107+ </ MaybeSuspend >
108+ </ React . Suspense >
109+ ) ;
110+ }
111+
112+ await render ( < TestComponent suspend = { false } /> ) ;
113+
114+ expect ( screen . getByText ( 'Ready' ) ) . toBeOnTheScreen ( ) ;
115+
116+ await screen . rerender ( < TestComponent suspend /> ) ;
117+
118+ expect ( screen . getByText ( 'Loading...' ) ) . toBeOnTheScreen ( ) ;
119+ expect (
120+ screen . getByTestId ( 'hidden-target' , { includeHiddenElements : true } ) . props . style ,
121+ ) . toEqual ( {
122+ display : 'none' ,
123+ } ) ;
124+ } ) ;
125+
126+ test ( 'appends display none when suspending an element with existing style' , async ( ) => {
127+ const promise = new Promise < unknown > ( ( ) => { } ) ;
128+
129+ function TestComponent ( { suspend } : { suspend : boolean } ) {
130+ return (
131+ < React . Suspense fallback = { < Text > Loading...</ Text > } >
132+ < MaybeSuspend promise = { promise } suspend = { suspend } >
133+ < View style = { { opacity : 0.5 } } testID = "hidden-target" >
134+ < Text > Ready</ Text >
135+ </ View >
136+ </ MaybeSuspend >
137+ </ React . Suspense >
138+ ) ;
139+ }
140+
141+ await render ( < TestComponent suspend = { false } /> ) ;
142+
143+ expect ( screen . getByText ( 'Ready' ) ) . toBeOnTheScreen ( ) ;
144+
145+ await screen . rerender ( < TestComponent suspend /> ) ;
146+
147+ expect ( screen . getByText ( 'Loading...' ) ) . toBeOnTheScreen ( ) ;
148+ expect (
149+ screen . getByTestId ( 'hidden-target' , { includeHiddenElements : true } ) . props . style ,
150+ ) . toEqual ( [ { opacity : 0.5 } , { display : 'none' } ] ) ;
151+ } ) ;
152+ } ) ;
153+
71154describe ( 'component rendering' , ( ) => {
72155 test ( 'render accepts RCTText component' , async ( ) => {
73156 await render ( React . createElement ( 'RCTText' , { testID : 'text' } , 'Hello' ) ) ;
0 commit comments