|
| 1 | +import test from "ava"; |
| 2 | +import browserEnv from "browser-env"; |
| 3 | +/** @jsx createElement */ |
| 4 | +import { render, createElement } from "../src/didact"; |
| 5 | + |
| 6 | +// Create document global var |
| 7 | +browserEnv(["document"]); |
| 8 | + |
| 9 | +test.beforeEach(t => { |
| 10 | + const root = document.createElement("div"); |
| 11 | + document.body.appendChild(root); |
| 12 | + t.context.root = root; |
| 13 | +}); |
| 14 | + |
| 15 | +test.afterEach.always(t => { |
| 16 | + const root = t.context.root; |
| 17 | + root.innerHTML = ""; |
| 18 | + document.body.removeChild(root); |
| 19 | +}); |
| 20 | + |
| 21 | +test("render jsx div", t => { |
| 22 | + const root = t.context.root; |
| 23 | + const element = <div />; |
| 24 | + render(element, root); |
| 25 | + t.is(root.innerHTML, "<div></div>"); |
| 26 | +}); |
| 27 | + |
| 28 | +test("render div with children", t => { |
| 29 | + const root = t.context.root; |
| 30 | + const element = <div><b /><a href="foo" /></div>; |
| 31 | + render(element, root); |
| 32 | + t.is(root.innerHTML, '<div><b></b><a href="foo"></a></div>'); |
| 33 | +}); |
| 34 | + |
| 35 | +test("render div with props", t => { |
| 36 | + const root = t.context.root; |
| 37 | + const element = <div id="foo" />; |
| 38 | + render(element, root); |
| 39 | + t.is(root.innerHTML, '<div id="foo"></div>'); |
| 40 | +}); |
| 41 | + |
| 42 | +test("render span with text child", t => { |
| 43 | + const root = t.context.root; |
| 44 | + const element = <span>Foo</span>; |
| 45 | + render(element, root); |
| 46 | + t.is(root.innerHTML, "<span>Foo</span>"); |
| 47 | +}); |
0 commit comments