|
1 |
| -import { describe, it, expect, beforeAll, afterAll, mock } from "bun:test"; |
| 1 | +import { |
| 2 | + describe, |
| 3 | + it, |
| 4 | + expect, |
| 5 | + beforeAll, |
| 6 | + afterAll, |
| 7 | + mock, |
| 8 | + afterEach, |
| 9 | +} from "bun:test"; |
2 | 10 | import { GlobalRegistrator } from "@happy-dom/global-registrator";
|
3 | 11 | import { serialize } from "../serialization";
|
4 | 12 |
|
@@ -1794,14 +1802,50 @@ describe("utils", () => {
|
1794 | 1802 | expect(webComponent?.shadowRoot?.innerHTML).toBe(`<div>Barbara</div>`);
|
1795 | 1803 | });
|
1796 | 1804 |
|
1797 |
| - it.todo( |
1798 |
| - "should work dangerHTML to inject HTML in a web-component", |
1799 |
| - () => {}, |
1800 |
| - ); |
| 1805 | + it("should work with booleans and numbers in the same way than React", () => { |
| 1806 | + const Component = ({}, { h }: any) => |
| 1807 | + h(null, {}, [ |
| 1808 | + [null, {}, () => true && ["div", {}, "TRUE"]], |
| 1809 | + [null, {}, () => false && ["div", {}, "FALSE"]], |
| 1810 | + [null, {}, () => 1 && ["div", {}, "TRUE"]], |
| 1811 | + [null, {}, () => 0 && ["div", {}, "FALSE"]], |
| 1812 | + ]); |
| 1813 | + |
| 1814 | + customElements.define("bool-component", brisaElement(Component)); |
| 1815 | + |
| 1816 | + document.body.innerHTML = "<bool-component />"; |
| 1817 | + const boolComponent = document.querySelector( |
| 1818 | + "bool-component", |
| 1819 | + ) as HTMLElement; |
| 1820 | + |
| 1821 | + expect(boolComponent?.shadowRoot?.innerHTML).toBe( |
| 1822 | + "<div>TRUE</div><div>TRUE</div>0", |
| 1823 | + ); |
| 1824 | + }); |
| 1825 | + |
| 1826 | + it("should work with booleans and numbers from props in the same way than React", () => { |
| 1827 | + const Component = ({ first, second, third, fourth }: any, { h }: any) => |
| 1828 | + h(null, {}, [ |
| 1829 | + [null, {}, () => first.value && ["div", {}, "TRUE"]], |
| 1830 | + [null, {}, () => second.value && ["div", {}, "FALSE"]], |
| 1831 | + [null, {}, () => third.value && ["div", {}, "TRUE"]], |
| 1832 | + [null, {}, () => fourth.value && ["div", {}, "FALSE"]], |
| 1833 | + ]); |
1801 | 1834 |
|
1802 |
| - it.todo( |
1803 |
| - "should not be possible to inject HTML without dangerHTML", |
1804 |
| - () => {}, |
1805 |
| - ); |
| 1835 | + customElements.define( |
| 1836 | + "bool-component", |
| 1837 | + brisaElement(Component, ["first", "second", "third", "fourth"]), |
| 1838 | + ); |
| 1839 | + |
| 1840 | + document.body.innerHTML = |
| 1841 | + "<bool-component first='true' second='false' third='1' fourth='0' />"; |
| 1842 | + const boolComponent = document.querySelector( |
| 1843 | + "bool-component", |
| 1844 | + ) as HTMLElement; |
| 1845 | + |
| 1846 | + expect(boolComponent?.shadowRoot?.innerHTML).toBe( |
| 1847 | + "<div>TRUE</div><div>TRUE</div>0", |
| 1848 | + ); |
| 1849 | + }); |
1806 | 1850 | });
|
1807 | 1851 | });
|
0 commit comments