a post-component library for building user-interfaces on the web.
at main 41 lines 764 B view raw
1import { html } from 'dhtml' 2import { renderToString } from 'dhtml/server' 3import { assert, assert_eq, test } from '../../../scripts/test/test.ts' 4 5test('renderables work correctly', () => { 6 assert_eq( 7 renderToString( 8 html`${{ 9 render() { 10 return html`<h1>Hello, world!</h1>` 11 }, 12 }}`, 13 ), 14 '<?[><?[><h1>Hello, world!</h1><?]><?]>', 15 ) 16}) 17 18test('thrown errors directly propagate', () => { 19 const oops = new Error('oops') 20 try { 21 renderToString( 22 html`${{ 23 render() { 24 throw oops 25 }, 26 }}`, 27 ) 28 assert(false, 'Expected an error') 29 } catch {} 30}) 31 32test('renderables can throw instead of returning', () => { 33 assert_eq( 34 renderToString({ 35 render() { 36 throw html`this was thrown` 37 }, 38 }), 39 '<?[>this was thrown<?]>', 40 ) 41})