Skip to content

Commit fea5e4b

Browse files
committed
test: Add (failing) test case
1 parent c54c194 commit fea5e4b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/browser/index.test.jsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)