import { compile } from '../src'
function getString(src: string): string {
return compile(src).code.match(/_push\((.*)\)/)![1]
}
describe('element', () => {
test('basic elements', () => {
expect(getString(`
`)).toMatchInlineSnapshot(`"\`\`"`)
expect(getString(``)).toMatchInlineSnapshot(`"\`\`"`)
})
test('static attrs', () => {
expect(getString(``)).toMatchInlineSnapshot(
`"\`\`"`
)
})
test('nested elements', () => {
expect(
getString(`
`)
).toMatchInlineSnapshot(`"\`
\`"`)
})
test('void element', () => {
expect(getString(``)).toMatchInlineSnapshot(`"\`\`"`)
})
})
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(`hellobye
`)
).toMatchInlineSnapshot(
`"\`hellobye
\`"`
)
})
test('interpolation', () => {
expect(getString(`foo {{ bar }} baz`)).toMatchInlineSnapshot(
`"\`foo \${interpolate(_ctx.bar)} baz\`"`
)
})
test('nested elements with interpolation', () => {
expect(
getString(
`{{ foo }} barbaz {{ qux }}
`
)
).toMatchInlineSnapshot(
`"\`\${interpolate(_ctx.foo)} barbaz \${interpolate(_ctx.qux)}
\`"`
)
})
})