/** * @jest-environment node */ import { ssrRenderAttrs, ssrRenderClass, ssrRenderStyle, ssrRenderAttr } from '../src/helpers/ssrRenderAttrs' import { escapeHtml } from '@vue/shared' describe('ssr: renderAttrs', () => { test('ignore reserved props', () => { expect( ssrRenderAttrs({ key: 1, ref: () => {}, onClick: () => {} }) ).toBe('') }) test('normal attrs', () => { expect( ssrRenderAttrs({ id: 'foo', title: 'bar' }) ).toBe(` id="foo" title="bar"`) }) test('empty value attrs', () => { expect( ssrRenderAttrs({ 'data-v-abc': '' }) ).toBe(` data-v-abc`) }) test('escape attrs', () => { expect( ssrRenderAttrs({ id: '"> { expect( ssrRenderAttrs({ checked: true, multiple: false }) ).toBe(` checked`) // boolean attr w/ false should be ignored }) test('ignore falsy values', () => { expect( ssrRenderAttrs({ foo: false, title: null, baz: undefined }) ).toBe(` foo="false"`) // non boolean should render `false` as is }) test('ignore non-renderable values', () => { expect( ssrRenderAttrs({ foo: {}, bar: [], baz: () => {} }) ).toBe(``) }) test('props to attrs', () => { expect( ssrRenderAttrs({ readOnly: true, // simple lower case conversion htmlFor: 'foobar' // special cases }) ).toBe(` readonly for="foobar"`) }) test('preserve name on custom element', () => { expect( ssrRenderAttrs( { fooBar: 'ok' }, 'my-el' ) ).toBe(` fooBar="ok"`) }) }) describe('ssr: renderAttr', () => { test('basic', () => { expect(ssrRenderAttr('foo', 'bar')).toBe(` foo="bar"`) }) test('null and undefined', () => { expect(ssrRenderAttr('foo', null)).toBe(``) expect(ssrRenderAttr('foo', undefined)).toBe(``) }) test('escape', () => { expect(ssrRenderAttr('foo', '