const compiler = require('../lib')
function assertCodegen (template, templateCode, renderCode = `with(this){}`, options = {}) {
const res = compiler.compile(template, {
resourcePath: 'test.wxml',
mp: Object.assign({
minified: true,
isTest: true,
platform: 'mp-alipay'
}, options)
})
expect(res.template).toBe(templateCode)
expect(res.render).toBe(renderCode)
}
describe('mp:compiler-mp-alipay', () => {
it('generate v-for directive', () => {
assertCodegen(
'',
``
)
})
it('generate v-else-if with v-else directive', () => {
assertCodegen(
'helloworldbye',
`helloworldbye`
)
})
it('generate ref', () => {
assertCodegen(
'text',
`text`
)
assertCodegen(
'text123213',
`text123213`
)
assertCodegen(
'',
``
)
assertCodegen(
'',
``
)
})
it('generate default slot', () => {
assertCodegen(
'text',
`text`
)
assertCodegen(
'text123213',
`text123213`
)
assertCodegen(
'text',
`text`
)
})
it('generate class binding', () => {
assertCodegen(
'
1
',
`1`
)
assertCodegen(
`2
`,
`2`
)
assertCodegen(
'3
',
`3`
)
assertCodegen(
`4
`,
`4`
)
assertCodegen(
`5
`,
`5`
)
assertCodegen(
`6
`,
`6`
)
// assertCodegen(
// `6
`,
// `6`,
// `with(this){var c0=__get_class(computedClassObject,"container");$mp.data=Object.assign({},{$root:{c0:c0}})}`
// )
assertCodegen(
`7
`,
`7`
)
assertCodegen(
`8
`,
`8`
)
assertCodegen(
`9
`,
`9`
)
})
it('generate getPhoneNumber', () => {
assertCodegen(
'',
``
)
})
it('generate events with v-on directive', () => {
assertCodegen(
``,
``,
`with(this){var a0={color:"#4cd964",size:"22",type:"spinner"};$mp.data=Object.assign({},{$root:{a0:a0}})}`
)
assertCodegen(
``,
``
)
assertCodegen(
``,
``
)
assertCodegen(
``,
``
)
assertCodegen(
``,
``
)
assertCodegen(
``,
``
)
assertCodegen(
``,
``
)
})
})