Skip to content

Commit ebfaf5c

Browse files
committed
fix: 补充wx-if单测
1 parent c683d73 commit ebfaf5c

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

packages/webpack-plugin/test/platform/common/wx-if.spec.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,78 @@ describe('template if should transform correct', function () {
240240
const iosOutput = compileTemplateToIos(input)
241241
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"1"):createElement(getComponent("mpx-text"), null,"2"))')
242242
})
243+
244+
it('should handle multiple dynamic wx:elif', function () {
245+
const input = '<view><text wx:if="{{condition1}}">1</text><text wx:elif="{{condition2}}">2</text><text wx:elif="{{condition3}}">3</text></view>'
246+
const wxOutput = compileTemplateToWx(input)
247+
expect(wxOutput).toBe('<view><text wx:if="{{condition1}}">1</text><text wx:elif="{{condition2}}">2</text><text wx:elif="{{condition3}}">3</text></view>')
248+
249+
const iosOutput = compileTemplateToIos(input)
250+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition1)?createElement(getComponent("mpx-text"), null,"1"):(condition2)?createElement(getComponent("mpx-text"), null,"2"):(condition3)?createElement(getComponent("mpx-text"), null,"3"):null)')
251+
})
252+
253+
it('should handle multiple wx:elif with static false', function () {
254+
const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{false}}">2</text><text wx:elif="{{condition2}}">3</text></view>'
255+
const wxOutput = compileTemplateToWx(input)
256+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">1</text><text wx:elif="{{condition2}}">3</text></view>')
257+
258+
const iosOutput = compileTemplateToIos(input)
259+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"1"):(condition2)?createElement(getComponent("mpx-text"), null,"3"):null)')
260+
})
261+
262+
it('should handle multiple wx:elif with static true in middle', function () {
263+
const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{true}}">2</text><text wx:elif="{{condition2}}">3</text></view>'
264+
const wxOutput = compileTemplateToWx(input)
265+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">1</text><text wx:else>2</text></view>')
266+
267+
const iosOutput = compileTemplateToIos(input)
268+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"1"):createElement(getComponent("mpx-text"), null,"2"))')
269+
})
270+
271+
it('should handle static false wx:if with multiple wx:elif', function () {
272+
const input = '<view><text wx:if="{{false}}">1</text><text wx:elif="{{condition1}}">2</text><text wx:elif="{{condition2}}">3</text></view>'
273+
const wxOutput = compileTemplateToWx(input)
274+
expect(wxOutput).toBe('<view><text wx:if="{{condition1}}">2</text><text wx:elif="{{condition2}}">3</text></view>')
275+
276+
const iosOutput = compileTemplateToIos(input)
277+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition1)?createElement(getComponent("mpx-text"), null,"2"):(condition2)?createElement(getComponent("mpx-text"), null,"3"):null)')
278+
})
279+
280+
it('should handle static false wx:if with multiple static false wx:elif', function () {
281+
const input = '<view><text wx:if="{{false}}">1</text><text wx:elif="{{false}}">2</text><text wx:elif="{{false}}">3</text></view>'
282+
const wxOutput = compileTemplateToWx(input)
283+
expect(wxOutput).toBe('<view></view>')
284+
285+
const iosOutput = compileTemplateToIos(input)
286+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null)')
287+
})
288+
289+
it('should handle multiple wx:elif with wx:else', function () {
290+
const input = '<view><text wx:if="{{condition1}}">1</text><text wx:elif="{{condition2}}">2</text><text wx:elif="{{condition3}}">3</text><text wx:else>4</text></view>'
291+
const wxOutput = compileTemplateToWx(input)
292+
expect(wxOutput).toBe('<view><text wx:if="{{condition1}}">1</text><text wx:elif="{{condition2}}">2</text><text wx:elif="{{condition3}}">3</text><text wx:else>4</text></view>')
293+
294+
const iosOutput = compileTemplateToIos(input)
295+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition1)?createElement(getComponent("mpx-text"), null,"1"):(condition2)?createElement(getComponent("mpx-text"), null,"2"):(condition3)?createElement(getComponent("mpx-text"), null,"3"):createElement(getComponent("mpx-text"), null,"4"))')
296+
})
297+
298+
it('should handle static false wx:if with multiple wx:elif and wx:else', function () {
299+
const input = '<view><text wx:if="{{false}}">1</text><text wx:elif="{{false}}">2</text><text wx:elif="{{condition}}">3</text><text wx:else>4</text></view>'
300+
const wxOutput = compileTemplateToWx(input)
301+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">3</text><text wx:else>4</text></view>')
302+
303+
const iosOutput = compileTemplateToIos(input)
304+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"3"):createElement(getComponent("mpx-text"), null,"4"))')
305+
})
306+
307+
it('should handle static true in second wx:elif', function () {
308+
const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{false}}">2</text><text wx:elif="{{true}}">3</text><text wx:elif="{{condition2}}">4</text></view>'
309+
const wxOutput = compileTemplateToWx(input)
310+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">1</text><text wx:else>3</text></view>')
311+
312+
const iosOutput = compileTemplateToIos(input)
313+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"1"):createElement(getComponent("mpx-text"), null,"3"))')
314+
})
243315
})
244316

245317
describe('error cases', () => {

0 commit comments

Comments
 (0)