2020-02-02 22:08:20 -05:00
|
|
|
import { compile } from '../src'
|
2020-02-02 21:47:10 -05:00
|
|
|
|
2020-02-02 22:28:54 -05:00
|
|
|
function getString(src: string): string {
|
2020-02-02 21:47:10 -05:00
|
|
|
return compile(src).code.match(/_push\((.*)\)/)![1]
|
|
|
|
}
|
|
|
|
|
2020-02-02 22:28:54 -05:00
|
|
|
describe('element', () => {
|
2020-02-02 21:47:10 -05:00
|
|
|
test('basic elements', () => {
|
2020-02-02 22:28:54 -05:00
|
|
|
expect(getString(`<div></div>`)).toMatchInlineSnapshot(`"\`<div></div>\`"`)
|
|
|
|
expect(getString(`<div/>`)).toMatchInlineSnapshot(`"\`<div></div>\`"`)
|
2020-02-02 21:47:10 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('static attrs', () => {
|
2020-02-02 22:28:54 -05:00
|
|
|
expect(getString(`<div id="foo" class="bar"></div>`)).toMatchInlineSnapshot(
|
|
|
|
`"\`<div id=\\"foo\\" class=\\"bar\\"></div>\`"`
|
|
|
|
)
|
2020-02-02 21:47:10 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
test('nested elements', () => {
|
|
|
|
expect(
|
2020-02-02 22:28:54 -05:00
|
|
|
getString(`<div><span></span><span></span></div>`)
|
2020-02-02 21:47:10 -05:00
|
|
|
).toMatchInlineSnapshot(`"\`<div><span></span><span></span></div>\`"`)
|
|
|
|
})
|
2020-02-02 22:08:20 -05:00
|
|
|
|
2020-02-02 22:28:54 -05:00
|
|
|
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>\`"`)
|
|
|
|
})
|
|
|
|
|
2020-02-02 22:08:20 -05:00
|
|
|
test('nested elements with static text', () => {
|
|
|
|
expect(
|
2020-02-02 22:28:54 -05:00
|
|
|
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>`
|
|
|
|
)
|
2020-02-02 22:08:20 -05:00
|
|
|
).toMatchInlineSnapshot(
|
2020-02-02 22:28:54 -05:00
|
|
|
`"\`<div><span>\${interpolate(_ctx.foo)} bar</span><span>baz \${interpolate(_ctx.qux)}</span></div>\`"`
|
2020-02-02 22:08:20 -05:00
|
|
|
)
|
|
|
|
})
|
2020-02-02 21:47:10 -05:00
|
|
|
})
|