diff --git a/packages/solid/web/test/context.spec.tsx b/packages/solid/web/test/context.spec.tsx index 478436756..31b449f1e 100644 --- a/packages/solid/web/test/context.spec.tsx +++ b/packages/solid/web/test/context.spec.tsx @@ -110,7 +110,39 @@ describe("Testing Context", () => { expect(div.children[1].innerHTML).toBe("dark"); }); - const ThemeContextWithoutDefault = createContext(); + const ThemeContextWithUndefined = createContext("light"); + const ComponentWithUndefined = () => { + const theme = useContext(ThemeContextWithUndefined); + // ?? 'undefined' will never get reached + return
{theme ?? "undefined"}
; + }; + + it("should override when nesting", () => { + const div = document.createElement("div"); + render( + () => ( + <> + + + + + + + + + + + + ), + div + ); + expect(div.children[0].innerHTML!).toBe("light"); + expect(div.children[1].innerHTML!).toBe("dark"); + expect(div.children[2].innerHTML!).toBe("darker"); + expect(div.children[3].innerHTML!).toBe("light"); + }); + + const ThemeContextWithoutDefault = createContext(); const ComponentWithoutDefault = () => { const theme = useContext(ThemeContextWithoutDefault); return
{theme ?? "no-default"}
; @@ -124,6 +156,9 @@ describe("Testing Context", () => { + + + ), @@ -131,5 +166,6 @@ describe("Testing Context", () => { ); expect(div.children[0].innerHTML!).toBe("no-default"); expect(div.children[1].innerHTML!).toBe("dark"); + expect(div.children[2].innerHTML!).toBe("no-default"); }); });