刮刮前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

43 lines
1.3 KiB

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-qq'
}, options)
})
expect(res.template).toBe(templateCode)
expect(res.render).toBe(renderCode)
}
describe('mp:compiler-mp-qq', () => {
it('generate class', () => {
assertCodegen(
'<view class="a external-class c" :class="class1">hello world</view>',
'<view class="{{[\'a\',\'external-class\',\'c\',class1]}}">hello world</view>'
)
})
it('generate text trim', () => {
assertCodegen(
'<text>\nN: {{title}}\n′</text>',
'<text>{{\'N: \'+title+"\\\\n′"}}</text>'
)
assertCodegen(
'<text>我是第一行1\n我的第二行</text>',
'<text>我是第一行1\n我的第二行</text>'
)
assertCodegen(
'<text>我是第一行2\n我的第二行1{{title}}</text>',
'<text>{{"我是第一行2\\\\n我的第二行1"+title}}</text>'
)
assertCodegen(
`<text>我是第一行3
我的第二行2{{title}}</text>`,
'<text>{{"我是第一行3\\\\n 我的第二行2"+title}}</text>'
)
})
})