a post-component library for building user-interfaces on the web.

server: test nullish directives (#197)

authored by tombl.dev and committed by

GitHub d2f2ffc3 d93c9c84

+10 -5
+5 -5
src/server.ts
··· 117 117 } 118 118 119 119 function render_directive(value: unknown) { 120 - if (value === null) return '' 121 - 122 - assert(typeof value === 'function') 123 - // console.log('directive returned:', value()) 120 + // Treat null/undefined as no-op, matching client behavior. 121 + if (value == null) return '' 124 122 125 - return '' 123 + // In dev, ensure anything else is a function; on the server we don't execute it. 124 + assert(typeof value === 'function') 125 + return '' 126 126 } 127 127 128 128 function render_attribute(name: string, value: unknown) {
+5
src/server/tests/basic.test.ts
··· 74 74 assert_eq(calls, 0) // TODO: what should these look like on the server? 75 75 }) 76 76 77 + test('nullish directives are ignored', () => { 78 + assert_eq(renderToString(html`<p ${undefined}></p>`), '<?[><p ></p><?]>') 79 + assert_eq(renderToString(html`<div ${null}></div>`), '<?[><div ></div><?]>') 80 + }) 81 + 77 82 test('unquoted attributes', () => { 78 83 assert_eq(renderToString(html`<a href=${'/url'}></a>`), '<?[><a href="/url"></a><?]>') 79 84 assert_eq(renderToString(html`<details hidden=${false}></details>`), '<?[><details ></details><?]>')