Skip to content

Commit

Permalink
test(transformer): 修复测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche authored and luckyadam committed Apr 15, 2019
1 parent 2ede173 commit 89a0273
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 123 deletions.
184 changes: 92 additions & 92 deletions packages/taro-transformer-wx/__tests__/control-flow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ describe('if statement', () => {
let dom = null
if (a) {
if (c) {
dom = <A />
dom = <AA />
}
} else if (b) {
dom = <B />
dom = <BB />
} else {
dom = <C />
}
Expand All @@ -332,14 +332,14 @@ describe('if statement', () => {
<block>
<block wx:if=\"{{a}}\">
<block wx:if=\"{{c}}\">
<a __triggerObserer=\"{{ _triggerObserer }}\"></a>
<aa compid=\"{{$compid__0}}\"></aa>
</block>
</block>
<block wx:elif=\"{{b}}\">
<b __triggerObserer=\"{{ _triggerObserer }}\"></b>
<bb compid=\"{{$compid__1}}\"></bb>
</block>
<block wx:else>
<c __triggerObserer=\"{{ _triggerObserer }}\"></c>
<c compid=\"{{$compid__2}}\"></c>
</block>
</block>
</view>
Expand All @@ -355,10 +355,10 @@ describe('if statement', () => {
const { a, b, c, d, e, f, g } = this.props
let dom = null
if (a) {
dom = <A />
dom = <AA />
} else if (b) {
if (c) {
dom = <B />
dom = <BB />
}
} else {
dom = <C />
Expand All @@ -373,15 +373,15 @@ describe('if statement', () => {
<view>
<block>
<block wx:if=\"{{a}}\">
<a __triggerObserer=\"{{ _triggerObserer }}\"></a>
<aa compid=\"{{$compid__3}}\"></aa>
</block>
<block wx:elif=\"{{b}}\">
<block wx:if=\"{{c}}\">
<b __triggerObserer=\"{{ _triggerObserer }}\"></b>
<bb compid=\"{{$compid__4}}\"></bb>
</block>
</block>
<block wx:else>
<c __triggerObserer=\"{{ _triggerObserer }}\"></c>
<c compid=\"{{$compid__5}}\"></c>
</block>
</block>
</view>
Expand All @@ -398,11 +398,11 @@ describe('if statement', () => {
let dom = null
if (a) {
if (d) {
dom = <A />
dom = <AA />
}
} else if (b) {
if (c) {
dom = <B />
dom = <BB />
}
} else {
dom = <C />
Expand All @@ -418,16 +418,16 @@ describe('if statement', () => {
<block>
<block wx:if=\"{{a}}\">
<block wx:if=\"{{d}}\">
<a __triggerObserer=\"{{ _triggerObserer }}\"></a>
<aa compid=\"{{$compid__6}}\"></aa>
</block>
</block>
<block wx:elif=\"{{b}}\">
<block wx:if=\"{{c}}\">
<b __triggerObserer=\"{{ _triggerObserer }}\"></b>
<bb compid=\"{{$compid__7}}\"></bb>
</block>
</block>
<block wx:else>
<c __triggerObserer=\"{{ _triggerObserer }}\"></c>
<c compid=\"{{$compid__8}}\"></c>
</block>
</block>
</view>
Expand All @@ -444,13 +444,13 @@ describe('if statement', () => {
let dom = null
if (a) {
if (d) {
dom = <A />
dom = <AA />
} else if (e) {
dom = <D />
}
} else if (b) {
if (c) {
dom = <B />
dom = <BB />
}
} else {
dom = <C />
Expand All @@ -466,19 +466,19 @@ describe('if statement', () => {
<block>
<block wx:if=\"{{a}}\">
<block wx:if=\"{{d}}\">
<a __triggerObserer=\"{{ _triggerObserer }}\"></a>
<aa compid=\"{{$compid__9}}\"></aa>
</block>
<block wx:elif=\"{{e}}\">
<d __triggerObserer=\"{{ _triggerObserer }}\"></d>
</block>
<d compid=\"{{$compid__10}}\"></d>
</block>
</block>
<block wx:elif=\"{{b}}\">
<block wx:if=\"{{c}}\">
<b __triggerObserer=\"{{ _triggerObserer }}\"></b>
<bb compid=\"{{$compid__11}}\"></bb>
</block>
</block>
<block wx:else>
<c __triggerObserer=\"{{ _triggerObserer }}\"></c>
<c compid=\"{{$compid__12}}\"></c>
</block>
</block>
</view>
Expand Down Expand Up @@ -507,15 +507,15 @@ describe('if statement', () => {

expect(template).toMatch(prettyPrint(`
<block>
<container __triggerObserer=\"{{ _triggerObserer }}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$original === 0}}\">
<image/>
</block>
<video wx:else></video>
<container compid=\"{{$compid__13}}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$original === 0}}\">
<image/>
</block>
</container>
</block>
<video wx:else></video>
</block>
</container>
</block>
`))
})

Expand All @@ -541,18 +541,18 @@ describe('if statement', () => {

expect(template).toMatch(prettyPrint(`
<block>
<container __triggerObserer=\"{{ _triggerObserer }}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$original === 0}}\">
<image/>
</block>
<block wx:elif=\"{{item.$original === 1}}\">
<test __triggerObserer=\"{{ _triggerObserer }}\"></test>
</block>
<video wx:else></video>
<container compid=\"{{$compid__15}}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$original === 0}}\">
<image/>
</block>
</container>
</block>
<block wx:elif=\"{{item.$original === 1}}\">
<test compid=\"{{item.$compid__14}}\"></test>
</block>
<video wx:else></video>
</block>
</container>
</block>
`))
})

Expand All @@ -576,18 +576,18 @@ describe('if statement', () => {

expect(template).toMatch(prettyPrint(`
<block>
<container __triggerObserer=\"{{ _triggerObserer }}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$original === 0}}\">
<image/>
</block>
<block wx:elif=\"{{item.$original === 1}}\">
<test __triggerObserer=\"{{ _triggerObserer }}\"></test>
</block>
<block wx:else></block>
<container compid=\"{{$compid__17}}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$original === 0}}\">
<image/>
</block>
</container>
</block>
<block wx:elif=\"{{item.$original === 1}}\">
<test compid=\"{{item.$compid__16}}\"></test>
</block>
<block wx:else></block>
</block>
</container>
</block>
`))
})

Expand All @@ -611,18 +611,18 @@ describe('if statement', () => {

expect(template).toMatch(prettyPrint(`
<block>
<container __triggerObserer=\"{{ _triggerObserer }}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$loopState__temp2}}\">
<image/>
</block>
<block wx:elif=\"{{item.$original === 1}}\">
<test __triggerObserer=\"{{ _triggerObserer }}\"></test>
</block>
<block wx:else></block>
<container compid=\"{{$compid__19}}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$loopState__temp2}}\">
<image/>
</block>
</container>
</block>
<block wx:elif=\"{{item.$original === 1}}\">
<test compid=\"{{item.$compid__18}}\"></test>
</block>
<block wx:else></block>
</block>
</container>
</block>
`))
})

Expand All @@ -646,18 +646,18 @@ describe('if statement', () => {

expect(template).toMatch(prettyPrint(`
<block>
<container __triggerObserer=\"{{ _triggerObserer }}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$loopState__temp2}}\">
<image src=\"{{item.$loopState__temp4}}\" />
</block>
<block wx:elif=\"{{item.$original === 1}}\">
<test __triggerObserer=\"{{ _triggerObserer }}\"></test>
</block>
<block wx:else></block>
<container compid=\"{{$compid__21}}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$loopState__temp2}}\">
<image src=\"{{item.$loopState__temp4}}\" />
</block>
</container>
</block>
<block wx:elif=\"{{item.$original === 1}}\">
<test compid=\"{{item.$compid__20}}\"></test>
</block>
<block wx:else></block>
</block>
</container>
</block>
`))
})

Expand All @@ -682,18 +682,18 @@ describe('if statement', () => {

expect(template).toMatch(prettyPrint(`
<block>
<container __triggerObserer=\"{{ _triggerObserer }}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$loopState__temp2}}\">
<image src=\"{{item.$loopState__temp4}}\" />
</block>
<block wx:if=\"{{item.$original === 1}}\">
<test __triggerObserer=\"{{ _triggerObserer }}\"></test>
</block>
<block wx:else></block>
<container compid=\"{{$compid__23}}\">
<block wx:for=\"{{loopArray0}}\" wx:for-item=\"item\">
<block wx:if=\"{{item.$loopState__temp2}}\">
<image src=\"{{item.$loopState__temp4}}\" />
</block>
</container>
</block>
<block wx:if=\"{{item.$original === 1}}\">
<test compid=\"{{item.$compid__22}}\"></test>
</block>
<block wx:else></block>
</block>
</container>
</block>
`))
})
})
Expand Down Expand Up @@ -721,14 +721,14 @@ describe('if statement', () => {
<block>
<view>
<block>
<block wx:if="{{current === 0}}">
<home __triggerObserer="{{ _triggerObserer }}"></home>
<block wx:if=\"{{current === 0}}\">
<home compid=\"{{$compid__24}}\"></home>
</block>
<block wx:elif="{{current === 1}}">
<goods __triggerObserer="{{ _triggerObserer }}"></goods>
<block wx:elif=\"{{current === 1}}\">
<goods compid=\"{{$compid__25}}\"></goods>
</block>
<block wx:elif="{{current === 2}}">
<order __triggerObserer="{{ _triggerObserer }}"></order>
<block wx:elif=\"{{current === 2}}\">
<order compid=\"{{$compid__26}}\"></order>
</block>
</block>
</view>
Expand Down Expand Up @@ -1218,7 +1218,7 @@ describe('inline 表达式', () => {
<block>
<view>
<block wx:if=\"{{!text}}\">
<btn __triggerObserer=\"{{ _triggerObserer }}\"></btn>
<btn compid=\"{{$compid__27}}\"></btn>
</block>
</view>
</block>
Expand Down
9 changes: 5 additions & 4 deletions packages/taro-transformer-wx/__tests__/loop.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,7 @@ describe('loop', () => {
)
})

expect(template).toMatch(`wx:key="item"`)
expect(template).toMatch(`wx:key="$original"`)
})

test('能使用 key 2', () => {
Expand All @@ -2695,7 +2695,7 @@ describe('loop', () => {
)
})

expect(template).toMatch(`wx:key="id"`)
expect(template).toMatch(`wx:key="$original.id"`)
})

test('callee 支持复杂表达式', () => {
Expand Down Expand Up @@ -2814,17 +2814,18 @@ describe('loop', () => {
'颜色',
'大小'
])

expect(
instance.state.loopArray0.map(i =>
i.$anonymousCallee__1.map(a => a.$original)
i.$anonymousCallee__0.map(a => a.$original)
)
).toEqual(Object.keys(keys).map(key => Object.keys(keys[key]).map(i => i)))
expect(template).toMatch(
prettyPrint(`
<block>
<view wx:key="index" wx:for="{{loopArray0}}" wx:for-item="key" wx:for-index="index">
<view>{{key.$original}}</view>
<view wx:key="id" wx:for="{{key.$anonymousCallee__1}}" wx:for-item="value" wx:for-index="id">{{value.$original}}</view>
<view wx:key="id" wx:for="{{key.$anonymousCallee__0}}" wx:for-item="value" wx:for-index="id">{{value.$original}}</view>
</view>
</block>
`)
Expand Down
Loading

0 comments on commit 89a0273

Please sign in to comment.