Skip to content

Commit

Permalink
test(mp-compiler): 同步 css 绑定 style相关测试
Browse files Browse the repository at this point in the history
  • Loading branch information
Otto-J committed Jan 15, 2025
1 parent 9e573a1 commit 52dd8f8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions packages/uni-mp-compiler/__tests__/style.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,60 @@ font-size: 15px;
`<view style="{{'color:' + 'green' + ';' + ('font-size:' + '15px') + ';' + ('background-color:' + a) + ';' + ('font-weight:' + b) + ';' + (c + ':' + d) + ';' + e + ';' + f}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.handle(_ctx.bg), b: _ctx.fontWeight, c: _h(_ctx.padding), d: _ctx.box.padding, e: _s(_ctx.style), f: _s({ margin: '0px' }) }
}`
)

assert(
`<view :style="{}"/>`,
'<view style="{{{}}}"/>',
`(_ctx, _cache) => {
return {}
}`
)
assert(
`<view :style="{...{}}"/>`,
'<view style="{{a}}"/>',
`(_ctx, _cache) => {
return { a: _s({}) }
}`
)
assert(
`<view :style="{...{color:'red'}}"/>`,
'<view style="{{a}}"/>',
`(_ctx, _cache) => {
return { a: _s({ color: 'red' }) }
}`
)

assert(
`<view :style="{...(false==false?{}:{})}"/>`,
'<view style="{{a}}"/>',
`(_ctx, _cache) => {
return { a: _s(false == false ? {} : {}) }
}`
)

assert(
`<view :style="false==false?{}:{}"/>`,
'<view style="{{a}}"/>',
`(_ctx, _cache) => {
return { a: _s(false == false ? {} : {}) }
}`
)

assert(
`<view :style="[\'color:red\']"/>`,
'<view style="{{\'color:red\'}}"/>',
`(_ctx, _cache) => {
return {}
}`
)

assert(
'<view :style="[].length===0?{}:{}"></view>',
'<view style="{{a}}"></view>',
`(_ctx, _cache) => {
return { a: _s([].length === 0 ? {} : {}) }
}`
)
})
Expand Down

0 comments on commit 52dd8f8

Please sign in to comment.