File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -344,5 +344,45 @@ describe('web components', () => {
344344 } ) ;
345345 assert . equal ( getShadowHTML ( ) , '<p>Active theme: sunny</p>' ) ;
346346 } ) ;
347+
348+ it . only ( 'passes context over light DOM custom element boundaries' , async ( ) => {
349+ const Theme = createContext ( 'light' ) ;
350+
351+ function DisplayTheme ( ) {
352+ const theme = useContext ( Theme ) ;
353+ return < p > Active theme: { theme } </ p > ;
354+ }
355+
356+ function Parent ( { children, theme = 'dark' } ) {
357+ return (
358+ < Theme . Provider value = { theme } >
359+ < div class = "children" > { children } </ div >
360+ </ Theme . Provider >
361+ ) ;
362+ }
363+
364+ registerElement ( Parent , 'x-light-dom-parent' , [ 'theme' ] ) ;
365+ registerElement ( DisplayTheme , 'x-light-dom-child' , [ ] ) ;
366+
367+ const el = document . createElement ( 'x-light-dom-parent' ) ;
368+
369+ const noSlot = document . createElement ( 'x-light-dom-child' ) ;
370+ el . appendChild ( noSlot ) ;
371+
372+ root . appendChild ( el ) ;
373+ assert . equal (
374+ root . innerHTML ,
375+ '<x-light-dom-parent><div class="children"><x-light-dom-child><p>Active theme: dark</p></x-light-dom-child></div></x-light-dom-parent>'
376+ ) ;
377+
378+ // Trigger context update
379+ act ( ( ) => {
380+ el . setAttribute ( 'theme' , 'sunny' ) ;
381+ } ) ;
382+ assert . equal (
383+ root . innerHTML ,
384+ '<x-light-dom-parent><div class="children"><x-light-dom-child><p>Active theme: sunny</p></x-light-dom-child></div></x-light-dom-parent>'
385+ ) ;
386+ } ) ;
347387 } ) ;
348388} ) ;
You can’t perform that action at this time.
0 commit comments