@@ -70,6 +70,34 @@ describe('template if should transform correct', function () {
7070 'createElement(getComponent("mpx-text"), null,"1"))' )
7171 } )
7272
73+ it ( 'should keep node when condition is false' , function ( ) {
74+ const input = '<view><text wx:if="{{false}}">1</text></view>'
75+ const wxOutput = compileTemplateToWx ( input )
76+ expect ( wxOutput ) . toBe ( '<view></view>' )
77+
78+ const iosOutput = compileTemplateToIos ( input )
79+ expect ( iosOutput ) . toBe ( 'createElement(getComponent("mpx-view"), null)' )
80+ } )
81+
82+ it ( 'should keep node when wx:elif condition is true' , function ( ) {
83+ const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{true}}">2</text></view>'
84+ const wxOutput = compileTemplateToWx ( input )
85+ expect ( wxOutput ) . toBe ( '<view><text wx:if="{{condition}}">1</text><text wx:else>2</text></view>' )
86+
87+ const iosOutput = compileTemplateToIos ( input )
88+ expect ( iosOutput ) . toBe ( 'createElement(getComponent("mpx-view"), null,(condition)?' +
89+ 'createElement(getComponent("mpx-text"), null,"1"):createElement(getComponent("mpx-text"), null,"2"))' )
90+ } )
91+
92+ it ( 'should remove node when wx:elif condition is false' , function ( ) {
93+ const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{false}}">2</text></view>'
94+ const wxOutput = compileTemplateToWx ( input )
95+ expect ( wxOutput ) . toBe ( '<view><text wx:if="{{condition}}">1</text></view>' )
96+
97+ const iosOutput = compileTemplateToIos ( input )
98+ expect ( iosOutput ) . toBe ( 'createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"1"):null)' )
99+ } )
100+
73101 it ( 'should handle __mpx_mode__ in condition' , function ( ) {
74102 const input = `
75103 <view>
0 commit comments