|
| 1 | +import { makeRender } from './_utils' |
| 2 | +import { template } from '../src/dom/template' |
| 3 | + |
| 4 | +const define = makeRender() |
| 5 | + |
| 6 | +describe('renderer: element', () => { |
| 7 | + it('should create an element', () => { |
| 8 | + const { html } = define({ |
| 9 | + render() { |
| 10 | + return template(`<div>`)() |
| 11 | + }, |
| 12 | + }).render() |
| 13 | + |
| 14 | + expect(html()).toBe('<div></div>') |
| 15 | + }) |
| 16 | + |
| 17 | + it('should create an element with props', () => { |
| 18 | + const { html } = define({ |
| 19 | + render() { |
| 20 | + return template(`<div id="foo" class="bar">`)() |
| 21 | + }, |
| 22 | + }).render() |
| 23 | + |
| 24 | + expect(html()).toBe('<div id="foo" class="bar"></div>') |
| 25 | + }) |
| 26 | + |
| 27 | + it('should create an element with direct text children', () => { |
| 28 | + const { html } = define({ |
| 29 | + render() { |
| 30 | + return template(`<div>foo bar`)() |
| 31 | + }, |
| 32 | + }).render() |
| 33 | + |
| 34 | + expect(html()).toBe('<div>foo bar</div>') |
| 35 | + }) |
| 36 | + |
| 37 | + it('should create an element with direct text children and props', () => { |
| 38 | + const { html } = define({ |
| 39 | + render() { |
| 40 | + return template(`<div id="foo">bar`)() |
| 41 | + }, |
| 42 | + }).render() |
| 43 | + |
| 44 | + expect(html()).toBe('<div id="foo">bar</div>') |
| 45 | + }) |
| 46 | + |
| 47 | + it.fails('should update an element tag which is already mounted', () => { |
| 48 | + const { html } = define({ |
| 49 | + render() { |
| 50 | + return template(`<div>foo`)() |
| 51 | + }, |
| 52 | + }).render() |
| 53 | + expect(html()).toBe('<div>foo</div>') |
| 54 | + |
| 55 | + define({ |
| 56 | + render() { |
| 57 | + return template(`<span>foo`)() |
| 58 | + }, |
| 59 | + }).render() |
| 60 | + expect(html()).toBe('<span>foo</span>') |
| 61 | + }) |
| 62 | + |
| 63 | + it.fails('should update element props which is already mounted', () => { |
| 64 | + const { html } = define({ |
| 65 | + render() { |
| 66 | + return template(`<div id="baz">foo`)() |
| 67 | + }, |
| 68 | + }).render() |
| 69 | + expect(html()).toBe('<div id="baz">foo</div>') |
| 70 | + |
| 71 | + define({ |
| 72 | + render() { |
| 73 | + return template(`<div id="baz" class="bar">foo`)() |
| 74 | + }, |
| 75 | + }).render() |
| 76 | + expect(html()).toBe('<div id="baz" class="bar">foo</div>') |
| 77 | + }) |
| 78 | +}) |
0 commit comments