wip(compiler-ssr): v-html, v-text & textarea value
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
import { compile } from '../src'
|
||||
|
||||
function getString(src: string): string {
|
||||
return compile(src).code.match(/_push\((.*)\)/)![1]
|
||||
}
|
||||
|
||||
describe('element', () => {
|
||||
test('basic elements', () => {
|
||||
expect(getString(`<div></div>`)).toMatchInlineSnapshot(`"\`<div></div>\`"`)
|
||||
expect(getString(`<div/>`)).toMatchInlineSnapshot(`"\`<div></div>\`"`)
|
||||
})
|
||||
|
||||
test('static attrs', () => {
|
||||
expect(getString(`<div id="foo" class="bar"></div>`)).toMatchInlineSnapshot(
|
||||
`"\`<div id=\\"foo\\" class=\\"bar\\"></div>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('nested elements', () => {
|
||||
expect(
|
||||
getString(`<div><span></span><span></span></div>`)
|
||||
).toMatchInlineSnapshot(`"\`<div><span></span><span></span></div>\`"`)
|
||||
})
|
||||
|
||||
test('void element', () => {
|
||||
expect(getString(`<input>`)).toMatchInlineSnapshot(`"\`<input>\`"`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('text', () => {
|
||||
test('static text', () => {
|
||||
expect(getString(`foo`)).toMatchInlineSnapshot(`"\`foo\`"`)
|
||||
})
|
||||
|
||||
test('static text escape', () => {
|
||||
expect(getString(`<foo>`)).toMatchInlineSnapshot(`"\`<foo>\`"`)
|
||||
})
|
||||
|
||||
test('nested elements with static text', () => {
|
||||
expect(
|
||||
getString(`<div><span>hello</span><span>bye</span></div>`)
|
||||
).toMatchInlineSnapshot(
|
||||
`"\`<div><span>hello</span><span>bye</span></div>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('interpolation', () => {
|
||||
expect(getString(`foo {{ bar }} baz`)).toMatchInlineSnapshot(
|
||||
`"\`foo \${interpolate(_ctx.bar)} baz\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('nested elements with interpolation', () => {
|
||||
expect(
|
||||
getString(
|
||||
`<div><span>{{ foo }} bar</span><span>baz {{ qux }}</span></div>`
|
||||
)
|
||||
).toMatchInlineSnapshot(
|
||||
`"\`<div><span>\${interpolate(_ctx.foo)} bar</span><span>baz \${interpolate(_ctx.qux)}</span></div>\`"`
|
||||
)
|
||||
})
|
||||
})
|
||||
52
packages/compiler-ssr/__tests__/ssrElement.spec.ts
Normal file
52
packages/compiler-ssr/__tests__/ssrElement.spec.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { getCompiledString } from './utils'
|
||||
|
||||
describe('element', () => {
|
||||
test('basic elements', () => {
|
||||
expect(getCompiledString(`<div></div>`)).toMatchInlineSnapshot(
|
||||
`"\`<div></div>\`"`
|
||||
)
|
||||
expect(getCompiledString(`<div/>`)).toMatchInlineSnapshot(
|
||||
`"\`<div></div>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('static attrs', () => {
|
||||
expect(
|
||||
getCompiledString(`<div id="foo" class="bar"></div>`)
|
||||
).toMatchInlineSnapshot(`"\`<div id=\\"foo\\" class=\\"bar\\"></div>\`"`)
|
||||
})
|
||||
|
||||
test('nested elements', () => {
|
||||
expect(
|
||||
getCompiledString(`<div><span></span><span></span></div>`)
|
||||
).toMatchInlineSnapshot(`"\`<div><span></span><span></span></div>\`"`)
|
||||
})
|
||||
|
||||
test('void element', () => {
|
||||
expect(getCompiledString(`<input>`)).toMatchInlineSnapshot(`"\`<input>\`"`)
|
||||
})
|
||||
|
||||
test('v-html', () => {
|
||||
expect(getCompiledString(`<div v-html="foo"/>`)).toMatchInlineSnapshot(
|
||||
`"\`<div>\${_ctx.foo}</div>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('v-text', () => {
|
||||
expect(getCompiledString(`<div v-text="foo"/>`)).toMatchInlineSnapshot(
|
||||
`"\`<div>\${interpolate(_ctx.foo)}</div>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('<textarea> with dynamic value', () => {
|
||||
expect(getCompiledString(`<textarea :value="foo"/>`)).toMatchInlineSnapshot(
|
||||
`"\`<textarea>\${interpolate(_ctx.foo)}</textarea>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('<textarea> with static value', () => {
|
||||
expect(
|
||||
getCompiledString(`<textarea value="fo>o"/>`)
|
||||
).toMatchInlineSnapshot(`"\`<textarea>fo>o</textarea>\`"`)
|
||||
})
|
||||
})
|
||||
37
packages/compiler-ssr/__tests__/ssrText.spec.ts
Normal file
37
packages/compiler-ssr/__tests__/ssrText.spec.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { getCompiledString } from './utils'
|
||||
|
||||
describe('text', () => {
|
||||
test('static text', () => {
|
||||
expect(getCompiledString(`foo`)).toMatchInlineSnapshot(`"\`foo\`"`)
|
||||
})
|
||||
|
||||
test('static text escape', () => {
|
||||
expect(getCompiledString(`<foo>`)).toMatchInlineSnapshot(
|
||||
`"\`<foo>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('nested elements with static text', () => {
|
||||
expect(
|
||||
getCompiledString(`<div><span>hello</span><span>bye</span></div>`)
|
||||
).toMatchInlineSnapshot(
|
||||
`"\`<div><span>hello</span><span>bye</span></div>\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('interpolation', () => {
|
||||
expect(getCompiledString(`foo {{ bar }} baz`)).toMatchInlineSnapshot(
|
||||
`"\`foo \${interpolate(_ctx.bar)} baz\`"`
|
||||
)
|
||||
})
|
||||
|
||||
test('nested elements with interpolation', () => {
|
||||
expect(
|
||||
getCompiledString(
|
||||
`<div><span>{{ foo }} bar</span><span>baz {{ qux }}</span></div>`
|
||||
)
|
||||
).toMatchInlineSnapshot(
|
||||
`"\`<div><span>\${interpolate(_ctx.foo)} bar</span><span>baz \${interpolate(_ctx.qux)}</span></div>\`"`
|
||||
)
|
||||
})
|
||||
})
|
||||
5
packages/compiler-ssr/__tests__/utils.ts
Normal file
5
packages/compiler-ssr/__tests__/utils.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { compile } from '../src'
|
||||
|
||||
export function getCompiledString(src: string): string {
|
||||
return compile(src).code.match(/_push\((.*)\)/)![1]
|
||||
}
|
||||
Reference in New Issue
Block a user