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-weixin'
}, options)
})
expect(res.template).toBe(templateCode)
if (typeof renderCode === 'function') {
renderCode(res)
} else {
expect(res.render).toBe(renderCode)
}
}
describe('mp:compiler-mp-weixin', () => {
it('generate scoped slot', () => {
assertCodegen(
'{{ bar.foo }}',
'',
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'{{ bar.foo }}',
'',
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
})
it('generate named scoped slot', () => {
assertCodegen(
'{{ bar.foo }}',
'',
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
)
assertCodegen(
'{{ bar.foo }}',
'',
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
)
})
it('generate scoped slot with multiline v-if', () => {
assertCodegen(
'{{ bar.foo }}',
'',
function (res) {
expect(res.generic[0]).toBe('test-foo-default')
}
)
assertCodegen(
'{{ bar.foo }}',
'',
function (res) {
expect(res.generic[0]).toBe('test-foo-foo')
}
)
})
it('generate scoped slot', () => {
assertCodegen( // TODO vue-id
'{{ user.lastName }}',
'',
function (res) {
expect(res.componentGenerics['scoped-slots-default']).toBe(true)
}
)
assertCodegen(
'{{ user.lastName }}',
'',
function (res) {
expect(res.componentGenerics['scoped-slots-header']).toBe(true)
}
)
})
it('generate page-meta', () => {
assertCodegen( // TODO vue-id
'',
''
)
})
it('generate v-slot', () => {
assertCodegen(
`
{{label}}
{{label}}
{{label}}
{{label}}
`,
''
)
})
})