@@ -42,46 +42,32 @@ describe('Portal', () => {
4242 } )
4343
4444 it ( 'should render portal children next to the body' , ( ) => {
45- const view = render (
46- < div >
45+ const { baseElement , container } = render (
46+ < div data-testid = "parent" >
4747 < Portal >
4848 < p > Anything must be visible</ p >
4949 </ Portal >
5050 </ div > ,
5151 )
5252
53- expect ( view . baseElement ) . toMatchInlineSnapshot ( `
54- <body>
55- <div>
56- <div />
57- </div>
58- <p>
59- Anything must be visible
60- </p>
61- </body>
62- ` )
53+ const portalContent = screen . getByText ( 'Anything must be visible' )
54+ expect ( portalContent ) . toBeVisible ( )
55+ expect ( baseElement ) . toContainElement ( portalContent )
56+ expect ( container . querySelector ( '[data-testid="parent"]' ) ) . not . toContainElement ( portalContent )
6357 } )
6458
6559 it ( 'should not render portal children next to the body if marked as `disabled`' , ( ) => {
66- const view = render (
67- < div >
60+ const { container } = render (
61+ < div data-testid = "parent" >
6862 < Portal disabled >
6963 < p > Anything must be visible</ p >
7064 </ Portal >
7165 </ div > ,
7266 )
7367
74- expect ( view . baseElement ) . toMatchInlineSnapshot ( `
75- <body>
76- <div>
77- <div>
78- <p>
79- Anything must be visible
80- </p>
81- </div>
82- </div>
83- </body>
84- ` )
68+ const portalContent = screen . getByText ( 'Anything must be visible' )
69+ expect ( portalContent ) . toBeVisible ( )
70+ expect ( container . querySelector ( '[data-testid="parent"]' ) ) . toContainElement ( portalContent )
8571 } )
8672
8773 it ( 'should render portal children inside a custom element' , ( ) => {
@@ -106,20 +92,14 @@ describe('Portal', () => {
10692 const div = document . createElement ( 'div' )
10793 document . body . appendChild ( div )
10894 const shadowRoot = div . attachShadow ( { mode : 'open' } )
109- const view = render (
95+ render (
11096 < EnvironmentProvider value = { ( ) => shadowRoot } >
11197 < Portal >
11298 < p > Anything must be visible</ p >
11399 </ Portal >
114100 </ EnvironmentProvider > ,
115101 )
116- expect ( view . baseElement ) . toMatchInlineSnapshot ( `
117- <body>
118- <div />
119- <div />
120- </body>
121- ` )
122- expect ( shadowRoot . innerHTML ) . toMatchInlineSnapshot ( `"<p>Anything must be visible</p>"` )
102+ expect ( shadowRoot . innerHTML ) . toBe ( '<p>Anything must be visible</p>' )
123103 } )
124104
125105 it ( 'should render twice if container was specified' , async ( ) => {
0 commit comments