2020-02-06 03:23:03 +08:00
|
|
|
import { compile } from '../src'
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
function compileWithWrapper(src: string) {
|
|
|
|
return compile(`<div>${src}</div>`)
|
|
|
|
}
|
|
|
|
|
2020-02-06 03:23:03 +08:00
|
|
|
describe('ssr: v-model', () => {
|
|
|
|
test('<input> (text types)', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(compileWithWrapper(`<input v-model="bar">`).code)
|
|
|
|
.toMatchInlineSnapshot(`
|
|
|
|
"const { ssrRenderAttr: _ssrRenderAttr, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-06 03:23:03 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input\${
|
|
|
|
_ssrRenderAttr(\\"value\\", _ctx.bar)
|
|
|
|
}></div>\`)
|
2020-02-06 03:23:03 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(compileWithWrapper(`<input type="email" v-model="bar">`).code)
|
2020-02-06 03:23:03 +08:00
|
|
|
.toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { ssrRenderAttr: _ssrRenderAttr, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-06 03:23:03 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input type=\\"email\\"\${
|
|
|
|
_ssrRenderAttr(\\"value\\", _ctx.bar)
|
|
|
|
}></div>\`)
|
2020-02-06 03:23:03 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('<input type="radio">', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(
|
|
|
|
compileWithWrapper(`<input type="radio" value="foo" v-model="bar">`).code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { ssrLooseEqual: _ssrLooseEqual, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input type=\\"radio\\" value=\\"foo\\"\${
|
|
|
|
(_ssrLooseEqual(_ctx.bar, \\"foo\\")) ? \\" checked\\" : \\"\\"
|
|
|
|
}></div>\`)
|
2020-02-06 03:23:03 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('<input type="checkbox"', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(compileWithWrapper(`<input type="checkbox" v-model="bar">`).code)
|
2020-02-06 03:23:03 +08:00
|
|
|
.toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { ssrLooseContain: _ssrLooseContain, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input type=\\"checkbox\\"\${
|
|
|
|
((Array.isArray(_ctx.bar))
|
|
|
|
? _ssrLooseContain(_ctx.bar, null)
|
|
|
|
: _ctx.bar) ? \\" checked\\" : \\"\\"
|
|
|
|
}></div>\`)
|
2020-02-06 03:23:03 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(
|
|
|
|
compileWithWrapper(`<input type="checkbox" value="foo" v-model="bar">`)
|
|
|
|
.code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { ssrLooseContain: _ssrLooseContain, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input type=\\"checkbox\\" value=\\"foo\\"\${
|
|
|
|
((Array.isArray(_ctx.bar))
|
|
|
|
? _ssrLooseContain(_ctx.bar, \\"foo\\")
|
|
|
|
: _ctx.bar) ? \\" checked\\" : \\"\\"
|
|
|
|
}></div>\`)
|
2020-02-06 03:23:03 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('<textarea>', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(compileWithWrapper(`<textarea v-model="foo">bar</textarea>`).code)
|
2020-02-06 03:23:03 +08:00
|
|
|
.toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { ssrRenderAttrs: _ssrRenderAttrs, ssrInterpolate: _ssrInterpolate } = require(\\"@vue/server-renderer\\")
|
|
|
|
|
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><textarea>\${
|
|
|
|
_ssrInterpolate(_ctx.foo)
|
|
|
|
}</textarea></div>\`)
|
2020-02-06 03:23:03 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
2020-02-06 06:01:00 +08:00
|
|
|
|
|
|
|
test('<input :type="x">', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(compileWithWrapper(`<input :type="x" v-model="foo">`).code)
|
2020-02-06 06:01:00 +08:00
|
|
|
.toMatchInlineSnapshot(`
|
2020-06-27 02:23:50 +08:00
|
|
|
"const { ssrRenderAttr: _ssrRenderAttr, ssrRenderDynamicModel: _ssrRenderDynamicModel, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-06 06:01:00 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input\${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderAttr(\\"type\\", _ctx.x)
|
2020-02-06 06:01:00 +08:00
|
|
|
}\${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderDynamicModel(_ctx.x, _ctx.foo, null)
|
2020-06-27 02:23:50 +08:00
|
|
|
}></div>\`)
|
2020-02-06 06:01:00 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(
|
|
|
|
compileWithWrapper(`<input :type="x" v-model="foo" value="bar">`).code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { ssrRenderAttr: _ssrRenderAttr, ssrRenderDynamicModel: _ssrRenderDynamicModel, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-06 06:01:00 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input\${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderAttr(\\"type\\", _ctx.x)
|
2020-02-06 06:01:00 +08:00
|
|
|
}\${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderDynamicModel(_ctx.x, _ctx.foo, \\"bar\\")
|
2020-06-27 02:23:50 +08:00
|
|
|
} value=\\"bar\\"></div>\`)
|
2020-02-06 06:01:00 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(
|
|
|
|
compileWithWrapper(`<input :type="x" v-model="foo" :value="bar">`).code
|
|
|
|
).toMatchInlineSnapshot(`
|
|
|
|
"const { ssrRenderAttr: _ssrRenderAttr, ssrRenderDynamicModel: _ssrRenderDynamicModel, ssrRenderAttrs: _ssrRenderAttrs } = require(\\"@vue/server-renderer\\")
|
2020-02-06 06:01:00 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input\${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderAttr(\\"type\\", _ctx.x)
|
2020-02-06 06:01:00 +08:00
|
|
|
}\${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderDynamicModel(_ctx.x, _ctx.foo, _ctx.bar)
|
2020-02-06 06:01:00 +08:00
|
|
|
}\${
|
2020-02-07 01:09:09 +08:00
|
|
|
_ssrRenderAttr(\\"value\\", _ctx.bar)
|
2020-06-27 02:23:50 +08:00
|
|
|
}></div>\`)
|
2020-02-06 06:01:00 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('<input v-bind="obj">', () => {
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(compileWithWrapper(`<input v-bind="obj" v-model="foo">`).code)
|
2020-02-06 06:01:00 +08:00
|
|
|
.toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { mergeProps: _mergeProps } = require(\\"vue\\")
|
|
|
|
const { ssrRenderAttrs: _ssrRenderAttrs, ssrGetDynamicModelProps: _ssrGetDynamicModelProps } = require(\\"@vue/server-renderer\\")
|
2020-02-06 06:01:00 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-02-06 06:01:00 +08:00
|
|
|
let _temp0
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input\${
|
|
|
|
_ssrRenderAttrs((_temp0 = _ctx.obj, _mergeProps(_temp0, _ssrGetDynamicModelProps(_temp0, _ctx.foo))))
|
|
|
|
}></div>\`)
|
2020-02-06 06:01:00 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
expect(
|
|
|
|
compileWithWrapper(`<input id="x" v-bind="obj" v-model="foo" class="y">`)
|
|
|
|
.code
|
|
|
|
).toMatchInlineSnapshot(`
|
2020-02-08 08:04:55 +08:00
|
|
|
"const { mergeProps: _mergeProps } = require(\\"vue\\")
|
|
|
|
const { ssrRenderAttrs: _ssrRenderAttrs, ssrGetDynamicModelProps: _ssrGetDynamicModelProps } = require(\\"@vue/server-renderer\\")
|
2020-02-06 06:01:00 +08:00
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
return function ssrRender(_ctx, _push, _parent, _attrs) {
|
2020-02-06 06:01:00 +08:00
|
|
|
let _temp0
|
|
|
|
|
2020-06-27 02:23:50 +08:00
|
|
|
_push(\`<div\${
|
|
|
|
_ssrRenderAttrs(_attrs)
|
|
|
|
}><input\${
|
|
|
|
_ssrRenderAttrs((_temp0 = _mergeProps({ id: \\"x\\" }, _ctx.obj, { class: \\"y\\" }), _mergeProps(_temp0, _ssrGetDynamicModelProps(_temp0, _ctx.foo))))
|
|
|
|
}></div>\`)
|
2020-02-06 06:01:00 +08:00
|
|
|
}"
|
|
|
|
`)
|
|
|
|
})
|
2020-02-06 03:23:03 +08:00
|
|
|
})
|