Skip to content

Commit 1199d6a

Browse files
author
boquanfu
committed
test: add cases for PageConstructor
1 parent a8f76d7 commit 1199d6a

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

test/env.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const renderComponent: (
55
template: string,
66
f: (
77
Component: adapter.ComponentConstructor,
8-
env: { Behavior: adapter.BehaviorConstructor },
8+
env: { Behavior: adapter.BehaviorConstructor, Page: adapter.PageConstructor },
99
) => void,
1010
) => adapter.glassEasel.GeneralComponent
1111

test/index.test.ts

+56
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,62 @@ describe('computed behavior', () => {
705705
expect(innerHTML(component)).toBe('<view>2</view>')
706706
})
707707

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+
708764
test('multiple usage in a single component', () => {
709765
let a1TriggerCount = 0
710766
let a2TriggerCount = 0

0 commit comments

Comments
 (0)