import { BindingTypes } from '@vue/compiler-core'
import { assert } from './testUtils'
describe('mp-alipay: transform ref', () => {
test('without ref', () => {
assert(
``,
``,
`(_ctx, _cache) => {
return {}
}`
)
assert(
``,
``,
`(_ctx, _cache) => {
return {}
}`
)
})
test('static ref', () => {
assert(
``,
``,
`import { resolveComponent as _resolveComponent } from "vue"
const __BINDING_COMPONENTS__ = '{"custom":{"name":"_component_custom","type":"unknown"}}'
if (!Array) {const _component_custom = _resolveComponent("custom");Math.max.call(null, _component_custom);}
export function render(_ctx, _cache) {
return {}
}`,
{
inline: false,
}
)
assert(
``,
``,
`import { resolveComponent as _resolveComponent, f as _f } from "vue"
const __BINDING_COMPONENTS__ = '{"custom":{"name":"_component_custom","type":"unknown"}}'
if (!Array) {const _component_custom = _resolveComponent("custom");Math.max.call(null, _component_custom);}
export function render(_ctx, _cache) {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }) }
}`,
{
inline: false,
}
)
})
test('static ref with inline', () => {
assert(
``,
``,
`(_ctx, _cache) => {
return { a: (_value, _refs) => { _refs['custom'] = _value; } }
}`
)
assert(
``,
``,
`(_ctx, _cache) => {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }), b: (_value, _refs) => { _refs['custom'] = _value; } }
}`
)
})
test('static ref with inline and setup-ref', () => {
assert(
``,
``,
`(_ctx, _cache) => {
return { a: (_value, _refs) => { _refs['custom'] = _value; custom.value = _value; } }
}`,
{
bindingMetadata: {
custom: BindingTypes.SETUP_REF,
},
}
)
})
test('dynamic ref', () => {
assert(
``,
``,
`import { resolveComponent as _resolveComponent } from "vue"
const __BINDING_COMPONENTS__ = '{"custom":{"name":"_component_custom","type":"unknown"}}'
if (!Array) {const _component_custom = _resolveComponent("custom");Math.max.call(null, _component_custom);}
export function render(_ctx, _cache) {
return { a: _ctx.custom }
}`,
{
inline: false,
}
)
assert(
``,
``,
`import { resolveComponent as _resolveComponent, f as _f } from "vue"
const __BINDING_COMPONENTS__ = '{"custom":{"name":"_component_custom","type":"unknown"}}'
if (!Array) {const _component_custom = _resolveComponent("custom");Math.max.call(null, _component_custom);}
export function render(_ctx, _cache) {
return { a: _f(_ctx.items, (item, k0, i0) => { return { a: '2a9ec0b0-0' + '-' + i0 }; }), b: _ctx.custom }
}`,
{
inline: false,
}
)
})
})