Commit 1199d6a boquanfu
committed
1 parent a8f76d7 commit 1199d6a Copy full SHA for 1199d6a
File tree 2 files changed +57
-1
lines changed
2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export const renderComponent: (
5
5
template : string ,
6
6
f : (
7
7
Component : adapter . ComponentConstructor ,
8
- env : { Behavior : adapter . BehaviorConstructor } ,
8
+ env : { Behavior : adapter . BehaviorConstructor , Page : adapter . PageConstructor } ,
9
9
) => void ,
10
10
) => adapter . glassEasel . GeneralComponent
11
11
Original file line number Diff line number Diff line change @@ -705,6 +705,62 @@ describe('computed behavior', () => {
705
705
expect ( innerHTML ( component ) ) . toBe ( '<view>2</view>' )
706
706
} )
707
707
708
+ test ( 'computed and watch inside behaviors' , ( ) => {
709
+ const behA = BehaviorWithComputed ( {
710
+ behaviors : [ computedBehavior ] ,
711
+ computed : {
712
+ b ( data ) {
713
+ return data . a * 2
714
+ } ,
715
+ } ,
716
+ watch : {
717
+ 'a, b' : function ( ) {
718
+ this . setData ( { c : this . data . a + this . data . b } )
719
+ } ,
720
+ } ,
721
+ attached ( ) {
722
+ this . onLoad ( )
723
+ } ,
724
+ } )
725
+ const component = renderComponent (
726
+ undefined ,
727
+ '<view>{{a}}+{{b}}={{c}}</view>' ,
728
+ ( _Component , { Page } ) => {
729
+ Page ( {
730
+ behaviors : [ behA ] ,
731
+ onLoad ( ) {
732
+ this . setData ( { a : 1 } )
733
+ }
734
+ } as any )
735
+ } ,
736
+ ) as any
737
+ expect ( innerHTML ( component ) ) . toBe ( '<view>1+2=3</view>' )
738
+ } )
739
+
740
+ test ( 'computed and watch inside page constructor' , ( ) => {
741
+ const component = renderComponent (
742
+ undefined ,
743
+ '<view>{{a}}+{{b}}={{c}}</view>' ,
744
+ ( _Component , { Page } ) => {
745
+ Page ( {
746
+ behaviors : [ computedBehavior ] ,
747
+ computed : {
748
+ b ( data ) {
749
+ return data . a * 2
750
+ } ,
751
+ c ( data ) {
752
+ return data . a + data . b
753
+ } ,
754
+ } ,
755
+ data : {
756
+ a : 1 ,
757
+ } ,
758
+ } as any )
759
+ } ,
760
+ ) as any
761
+ expect ( innerHTML ( component ) ) . toBe ( '<view>1+2=3</view>' )
762
+ } )
763
+
708
764
test ( 'multiple usage in a single component' , ( ) => {
709
765
let a1TriggerCount = 0
710
766
let a2TriggerCount = 0
You can’t perform that action at this time.
0 commit comments