You need to sign in or sign up before continuing.
提交 ed99f749 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

Merge branch 'dev' into alpha

<template>
<text>
count: {{count}}
</text>
</template>
<script setup>
const count = ref(0)
function getCount() : number {
return count.value
}
function setCount(newCount : number) {
count.value = newCount * 2
}
defineExpose({
count,
getCount,
setCount
})
</script>
<style>
</style>
\ No newline at end of file
<template>
<text>
count: {{count}}
</text>
</template>
<script>
export default {
name: "test-getter-setter-options",
data() {
return {
count: 0
};
},
methods: {
getCount() : number {
return this.count
},
setCount(newCount : number) {
this.count = newCount * 2
}
}
}
</script>
<style>
</style>
\ No newline at end of file
const PAGE_PATH_OPTIONS = '/pages/built-in/component/keep-alive/keep-alive-options'
const PAGE_PATH_COMPOSITION = '/pages/built-in/component/keep-alive/keep-alive-composition'
describe('keep-alive', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.includes('android')
const isIOS = platformInfo.includes('ios')
const isMP = platformInfo.startsWith('mp')
if(isMP) {
it('not support', async () => {
expect(1).toBe(1)
})
return
describe('keep-alive', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
if(isMP) {
it('not support', async () => {
expect(1).toBe(1)
})
return
}
let page = null
const testKeepAlive = async () => {
......
const PAGE_PATH_OPTIONS = '/pages/built-in/component/teleport/teleport-options'
const PAGE_PATH_COMPONSITION = '/pages/built-in/component/teleport/teleport-composition'
describe('teleport', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.includes('android')
const isIOS = platformInfo.includes('ios')
const isMP = platformInfo.startsWith('mp')
if(isMP || isIOS) {
it('not support', async () => {
expect(1).toBe(1)
})
return
describe('teleport', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isIOS = platformInfo.includes('ios')
const isMP = platformInfo.startsWith('mp')
if(isMP || isIOS) {
it('not support', async () => {
expect(1).toBe(1)
})
return
}
let page = null
......
......@@ -2,6 +2,11 @@
<view>
<call-easy-method ref="callEasyMethod1"></call-easy-method>
<custom-call-easy-method ref="customCallEasyMethod1"></custom-call-easy-method>
<test-getter-setter-composition ref="getterAndSetterComposition"></test-getter-setter-composition>
<test-getter-setter-options ref="getterAndSetterOptions"></test-getter-setter-options>
<view>
<text>getter-setter: <text id="getterAndSetter">{{JSON.stringify(getterAndSetterResult)}}</text></text>
</view>
</view>
</template>
......@@ -52,6 +57,48 @@ const callCustomMethodTest = (): string | null => {
return result
}
const getterAndSetterComposition = ref<TestGetterSetterCompositionComponentPublicInstance | null>(null)
const getterAndSetterOptions = ref<TestGetterSetterOptionsComponentPublicInstance | null>(null)
const getterAndSetterResult = ref<number[]>([])
const callGetterAndSetterCompositionGetCount = (): number => {
return getterAndSetterComposition.value!.getCount()
}
const callGetterAndSetterCompositionGetCountWithCallMethod = (): number => {
return getterAndSetterComposition.value!.$callMethod('getCount') as number
}
const callGetterAndSetterOptionsGetCount = (): number => {
return getterAndSetterOptions.value!.getCount()
}
const callGetterAndSetterOptionsGetCountWithCallMethod = (): number => {
return getterAndSetterOptions.value!.$callMethod('getCount') as number
}
const callGetterAndSetterCompositionSetCount = (count: number) => {
getterAndSetterComposition.value!.setCount(count)
}
const callGetterAndSetterCompositionSetCountWithCallMethod = (count: number) => {
getterAndSetterComposition.value!.$callMethod('setCount', count)
}
const callGetterAndSetterOptionsSetCount = (count: number) => {
getterAndSetterOptions.value!.setCount(count)
}
const callGetterAndSetterOptionsSetCountWithCallMethod = (count: number) => {
getterAndSetterOptions.value!.$callMethod('setCount', count)
}
const callGetterAndSetter = (): number[] => {
const result: number[] = []
callGetterAndSetterCompositionSetCount(1)
result.push(callGetterAndSetterCompositionGetCount())
callGetterAndSetterCompositionSetCountWithCallMethod(2)
result.push(callGetterAndSetterCompositionGetCountWithCallMethod())
callGetterAndSetterOptionsSetCount(3)
result.push(callGetterAndSetterOptionsGetCount())
callGetterAndSetterOptionsSetCountWithCallMethod(4)
result.push(callGetterAndSetterOptionsGetCountWithCallMethod())
getterAndSetterResult.value = result
return result
}
const delay = (): Promise<string> =>
new Promise((resolve, _) => {
setTimeout(() => {
......@@ -60,6 +107,7 @@ const delay = (): Promise<string> =>
})
const call = async (): Promise<void> => {
callGetterAndSetter()
callMethod()
callMethod1()
await delay()
......
......@@ -2,6 +2,11 @@
<view>
<call-easy-method ref="callEasyMethod1"></call-easy-method>
<custom-call-easy-method ref="customCallEasyMethod1"></custom-call-easy-method>
<test-getter-setter-composition ref="getterAndSetterComposition"></test-getter-setter-composition>
<test-getter-setter-options ref="getterAndSetterOptions"></test-getter-setter-options>
<view>
<text>getter-setter: <text id="getterAndSetter">{{JSON.stringify(getterAndSetterResult)}}</text></text>
</view>
</view>
</template>
......@@ -18,16 +23,23 @@ export default {
return {
callEasyMethod1: null as CallEasyMethodComponentPublicInstance | null,
customCallEasyMethod1: null as CustomCallEasyMethodComponentPublicInstance | null,
getterAndSetterComposition: null as TestGetterSetterCompositionComponentPublicInstance | null,
getterAndSetterOptions: null as TestGetterSetterOptionsComponentPublicInstance | null,
getterAndSetterResult: [] as number[]
}
},
onReady() {
// 通过组件 ref 属性获取组件实例, 组件标签名首字母大写,驼峰+ComponentPublicInstance
this.callEasyMethod1 = this.$refs['callEasyMethod1'] as CallEasyMethodComponentPublicInstance
this.customCallEasyMethod1 = this.$refs['customCallEasyMethod1'] as CustomCallEasyMethodComponentPublicInstance
this.getterAndSetterComposition = this.$refs['getterAndSetterComposition'] as TestGetterSetterCompositionComponentPublicInstance
this.getterAndSetterOptions = this.$refs['getterAndSetterOptions'] as TestGetterSetterOptionsComponentPublicInstance
this.call()
},
methods: {
async call(): Promise<void> {
this.callGetterAndSetter()
this.callCustomMethod()
this.callMethod1()
await delay()
......@@ -74,6 +86,43 @@ export default {
const result = this.customCallEasyMethod1?.foo?.() as string
return result
},
callGetterAndSetter(): number[] {
const result:number[] = []
this.callGetterAndSetterCompositionSetCount(1)
result.push(this.callGetterAndSetterCompositionGetCount())
this.callGetterAndSetterCompositionSetCountWithCallMethod(2)
result.push(this.callGetterAndSetterCompositionGetCountWithCallMethod())
this.callGetterAndSetterOptionsSetCount(3)
result.push(this.callGetterAndSetterOptionsGetCount())
this.callGetterAndSetterOptionsSetCountWithCallMethod(4)
result.push(this.callGetterAndSetterOptionsGetCountWithCallMethod())
this.getterAndSetterResult = result
return result
},
callGetterAndSetterCompositionGetCount(): number {
return this.getterAndSetterComposition!.getCount()
},
callGetterAndSetterCompositionGetCountWithCallMethod(): number {
return this.getterAndSetterComposition!.$callMethod('getCount') as number
},
callGetterAndSetterOptionsGetCount(): number {
return this.getterAndSetterOptions!.getCount()
},
callGetterAndSetterOptionsGetCountWithCallMethod(): number {
return this.getterAndSetterOptions!.$callMethod('getCount') as number
},
callGetterAndSetterCompositionSetCount(count: number) {
this.getterAndSetterComposition!.setCount(count)
},
callGetterAndSetterCompositionSetCountWithCallMethod(count: number) {
this.getterAndSetterComposition!.$callMethod('setCount', count)
},
callGetterAndSetterOptionsSetCount(count: number) {
this.getterAndSetterOptions!.setCount(count)
},
callGetterAndSetterOptionsSetCountWithCallMethod(count: number) {
this.getterAndSetterOptions!.$callMethod('setCount', count)
}
}
}
</script>
\ No newline at end of file
const PAGE_PATH = "/pages/component-instance/methods/call-method-easycom-uni-modules-composition"
const platformInfo = process.env.uniTestPlatformInfo.toLowerCase()
const isIOS = platformInfo.startsWith('ios')
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('callMethodTest', async () => {
// a[[]] only issue 8582
if (isWeb || isMP) {
expect(1).toBe(1)
return
}
// ios_simulator ios 17.0
// xcodoe 15 以下的版本环境不满足
if (
isIOS &&
(platformInfo.indexOf('14.') != -1 ||
platformInfo.indexOf('13.') != -1 ||
platformInfo.indexOf('12.') != -1)
) {
expect(1).toBe(1)
return
}
const delay = () =>
new Promise((resolve, _) => {
setTimeout(() => {
resolve('')
}, 1500)
})
await page.callMethod('onButtonClick')
await delay()
const resStr1 = await page.$("#isNumListValid")
const resStr2 = await page.$("#isObjListValid")
expect(await resStr1.text()).toBe(`true`)
expect(await resStr2.text()).toBe(`true`)
})
<template>
<view>
<call-easy-method-uni-modules ref="callEasyMethod1"></call-easy-method-uni-modules>
<!-- #ifdef APP -->
<!-- #ifdef APP-ANDROID || APP-IOS || APP-HARMONY -->
<!-- 在兼容组件中 ios 返回非普通对象数据,比如 Map 数据时候会被 jscore 统一处理为 object,和安卓产生了差异 -->
<!-- 测试用例用来验证返回数据特殊,安卓和其他平台无此限制 -->
<view>---</view>
<test-props id="btn1" :numList="numList" :objList='objList' @buttonclick='onButtonClick'
@numListChange='numListChange' @objListChange='objListChange'
......@@ -22,7 +24,7 @@
import { testInOtherFile } from './call-method-easycom-uni-modules'
import { ref, isProxy, isRef } from 'vue'
// #ifdef APP
// #ifdef APP-ANDROID || APP-IOS
import { PropsChangeEvent } from '@/uni_modules/test-props'
// #endif
......@@ -81,12 +83,11 @@
}
// #endif
// #ifdef APP-IOS
// #ifdef APP-IOS || APP-HARMONY
const numListChange = (res : any) => {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
console.log('is array',isArray,'is length>0',isLengthGt0,'res',isArray && isLengthGt0);
isNumListValid.value = isArray && isLengthGt0
}
// #endif
......@@ -101,12 +102,11 @@
}
// #endif
// #ifdef APP-IOS
// #ifdef APP-IOS || APP-HARMONY
const objListChange = (res : any) => {
const value = res['detail']!['value'] as any[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
console.log('is array',isArray,'is length>0',isLengthGt0,'res',isArray && isLengthGt0);
isObjListValid.value = isArray && isLengthGt0
}
// #endif
......
const PAGE_PATH = "/pages/component-instance/methods/call-method-easycom-uni-modules-options"
const platformInfo = process.env.uniTestPlatformInfo.toLowerCase()
const isIOS = platformInfo.startsWith('ios')
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
})
it('callMethodTest', async () => {
// app only issue 8582
if (isWeb || isMP) {
expect(1).toBe(1)
return
}
// ios_simulator ios 17.0
// xcodoe 15 以下的版本环境不满足
if (
isIOS &&
(platformInfo.indexOf('14.') != -1 ||
platformInfo.indexOf('13.') != -1 ||
platformInfo.indexOf('12.') != -1)
) {
expect(1).toBe(1)
return
}
const delay = () =>
new Promise((resolve, _) => {
setTimeout(() => {
resolve('')
}, 1500)
})
await page.callMethod('onButtonClick')
await delay()
const resStr1 = await page.$("#isNumListValid")
const resStr2 = await page.$("#isObjListValid")
expect(await resStr1.text()).toBe(`true`)
expect(await resStr2.text()).toBe(`true`)
})
......@@ -2,7 +2,9 @@
<view>
<call-easy-method-uni-modules ref="callEasyMethod1"></call-easy-method-uni-modules>
<!-- #ifdef APP -->
<!-- #ifdef APP-IOS || APP-ANDROID || APP-HARMONY -->
<!-- 在兼容组件中 ios 返回非普通对象数据,比如 Map 数据时候会被 jscore 统一处理为 object,和安卓产生了差异 -->
<!-- 测试用例用来验证返回数据特殊,安卓和其他平台无此限制 -->
<view>---</view>
<test-props id="btn1" :numList="numList" :objList='objList' @buttonclick='onButtonClick'
@numListChange='numListChange' @objListChange='objListChange'
......@@ -93,43 +95,43 @@
// #ifdef APP-ANDROID
numListChange(res : Map<string, Map<string, any>>) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isNumListValid = isArray && isLengthGt0
},
// #endif
// #ifdef APP-IOS
numListChange(res : any) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isNumListValid = isArray && isLengthGt0
},
// #endif
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isNumListValid = isArray && isLengthGt0
},
// #endif
// #ifdef APP-IOS || APP-HARMONY
numListChange(res : any) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isNumListValid = isArray && isLengthGt0
},
// #endif
// #ifdef APP-ANDROID
objListChange(res : Map<string, Map<string, any>>) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isObjListValid = isArray && isLengthGt0
},
// #endif
// #ifdef APP-IOS
objListChange(res : any) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isObjListValid = isArray && isLengthGt0
},
// #endif
onButtonClick() {
// 改变 props: 观察 props 返回值为非响应式值
console.log('button click');
this.numList = [3, 2, 1]
this.objList = [{ id: '3' }, { id: '4' }]
}
// #ifdef APP-ANDROID
objListChange(res : Map<string, Map<string, any>>) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isObjListValid = isArray && isLengthGt0
},
// #endif
// #ifdef APP-IOS || APP-HARMONY
objListChange(res : any) {
const value = res['detail']!['value'] as number[]
const isArray = Array.isArray(value)
const isLengthGt0 = value.length > 0
this.isObjListValid = isArray && isLengthGt0
},
// #endif
onButtonClick() {
// 改变 props: 观察 props 返回值为非响应式值
console.log('button click');
this.numList = [3, 2, 1]
this.objList = [{ id: '3' }, { id: '4' }]
}
}
}
</script>
const OPTIONS_PAGE_PATH = "/pages/component-instance/methods/call-method-easycom-uni-modules-options"
const COMPOSITION_PAGE_PATH = "/pages/component-instance/methods/call-method-easycom-uni-modules-composition"
const platformInfo = process.env.uniTestPlatformInfo.toLowerCase()
const isIOS = platformInfo.startsWith('ios')
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
describe('call method easycom uni modules', () => {
if (
isMP ||
isWeb ||
(
isIOS &&
(
platformInfo.indexOf('14.') != -1 ||
platformInfo.indexOf('13.') != -1 ||
platformInfo.indexOf('12.') != -1
)
)
) {
it('not support', async () => {
expect(1).toBe(1)
})
return
}
const test = async (pagePath) => {
page = await program.reLaunch(pagePath)
await page.waitFor('view')
await page.callMethod('onButtonClick')
await page.waitFor(1500)
const resStr1 = await page.$("#isNumListValid")
const resStr2 = await page.$("#isObjListValid")
expect(await resStr1.text()).toBe(`true`)
expect(await resStr2.text()).toBe(`true`)
}
it('选项式 API', async () => {
await test(OPTIONS_PAGE_PATH)
});
it('组合式 API', async () => {
await test(COMPOSITION_PAGE_PATH)
})
})
......@@ -12,6 +12,10 @@ describe('call-method-easycom', () => {
expect(result).toBe(title)
const customResult = await page.callMethod('callCustomMethodTest')
expect(customResult).toBe('custom foo')
const getterAndSetter = await page.$('#getterAndSetter')
const getterAndSetterText = await getterAndSetter.text()
expect(getterAndSetterText).toBe(JSON.stringify([2, 4, 6, 8]))
})
it('callMethodTest Composition API', async () => {
......@@ -22,5 +26,9 @@ describe('call-method-easycom', () => {
expect(result).toBe(title)
const customResult = await page.callMethod('callCustomMethodTest')
expect(customResult).toBe('custom foo')
const getterAndSetter = await page.$('#getterAndSetter')
const getterAndSetterText = await getterAndSetter.text()
expect(getterAndSetterText).toBe(JSON.stringify([2, 4, 6, 8]))
})
})
......@@ -70,9 +70,9 @@ describe('v-for', () => {
await page.waitFor(500)
const image = await program.screenshot({
fullPage: true
});
expect(image).toSaveImageSnapshot();
fullPage: true
});
expect(image).toSaveImageSnapshot();
}
it('v-for options API', async () => {
page = await program.reLaunch(OPTIONS_PAGE_PATH)
......
......@@ -7,7 +7,8 @@ describe('v-html', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isIOS = platformInfo.includes('ios')
const isMP = platformInfo.startsWith('mp')
if (isIOS || isMP) {
const isHarmony = platformInfo.includes('harmony')
if (isIOS || isMP || isHarmony) {
it("not support", async () => {
expect(1).toBe(1);
});
......@@ -15,22 +16,19 @@ describe('v-html', () => {
}
let page
const test = async () => {
const test = async (pagePath) => {
page = await program.reLaunch(pagePath)
await page.waitFor(700)
const image = await program.screenshot()
expect(image).toSaveImageSnapshot()
}
it('v-html options API', async () => {
page = await program.reLaunch(OPTIONS_PAGE_PATH)
await page.waitFor(700)
await test(page)
await test(OPTIONS_PAGE_PATH)
})
it('v-html composition API', async () => {
page = await program.reLaunch(COMPOSITION_PAGE_PATH)
await page.waitFor(700)
await test(page)
await test(COMPOSITION_PAGE_PATH)
})
})
\ No newline at end of file
......@@ -4,6 +4,7 @@ describe('v-model', () => {
let page
const platformInfo = process.env.uniTestPlatformInfo.toLowerCase()
const isIos = platformInfo.startsWith('ios')
const isHarmony = platformInfo.includes('harmony')
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
......@@ -17,8 +18,8 @@ describe('v-model', () => {
const str = await page.$('#str')
expect(await str.text()).toBe('new str')
if (!isIos) {
// TODO: ios 不支持 number & trim 修饰符
if (!isIos && !isHarmony) {
// TODO: ios & harmony 不支持 number & trim 修饰符
const modelNumInput = await page.$('#model-num')
await modelNumInput.input('123')
const typeofNum = await page.$('#typeof-num')
......
......@@ -27,7 +27,7 @@
</button>
<!-- #endif -->
<!-- TODO: ios 不支持 -->
<!-- #ifndef APP-IOS || MP -->
<!-- #ifndef APP-IOS || MP || APP-HARMONY -->
<button class="mb-10 btn" id="btn-once" @click.once="handleClick">@click once</button>
<!-- #endif -->
<view @click="handleClick">
......
......@@ -25,7 +25,7 @@
</button>
<!-- #endif -->
<!-- TODO: ios 不支持 -->
<!-- #ifndef APP-IOS || MP -->
<!-- #ifndef APP-IOS || MP || APP-HARMONY -->
<button class="mb-10 btn" id="btn-once" @click.once="handleClick">@click once</button>
<!-- #endif -->
<view @click="handleClick">
......
......@@ -6,6 +6,7 @@ describe('v-on', () => {
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isMP = platformInfo.startsWith('mp')
const isHarmony = platformInfo.includes('harmony')
let page
const test = async (pagePath) => {
......@@ -21,11 +22,11 @@ describe('v-on', () => {
await page.waitFor(500)
}
const supportedCount = isIOS ? '7' : isMP ? '5' : '8'
const supportedCount = (isIOS || isHarmony) ? '7' : isMP ? '5' : '8'
expect(await count.text()).toBe(supportedCount)
if (!isIOS && !isMP) {
if (!isIOS && !isMP && !isHarmony) {
const onceBtn = await page.$('#btn-once')
await onceBtn.tap()
expect(await count.text()).toBe(supportedCount)
......
......@@ -5,7 +5,7 @@
<text>show default true: {{dataInfo.showDefaultTrue}}</text>
<view class="mt-10 default-true" id="v-show-element-default-true" v-show="dataInfo.showDefaultTrue"></view>
<text>show default false: {{dataInfo.showDefaultFalse}}</text>
<view class="mt-10 default-false" id="v-show-element-default-false" v-show="dataInfo.showDefaultFalse"></view>
<view class="mt-10 default-false" id="v-show-element-default-false" v-show="dataInfo.showDefaultFalse"></view>
<Foo v-show="dataInfo.showDefaultFalse" />
</view>
</template>
......
......@@ -19,11 +19,14 @@ async function isElementShow(ele) {
describe('v-show', () => {
let page
const test = async (page) => {
const test = async (pagePath) => {
page = await program.reLaunch(pagePath)
await page.waitFor('view')
let dataInfo = await page.data('dataInfo')
expect(dataInfo.showDefaultTrue).toBe(true)
expect(dataInfo.showDefaultFalse).toBe(false)
await page.waitFor(100)
await page.waitFor(1000)
const vShowElementDefaultTrue = await page.$('#v-show-element-default-true')
expect(await isElementShow(vShowElementDefaultTrue)).toBe(true)
......@@ -61,16 +64,10 @@ describe('v-show', () => {
}
it('v-show options API', async () => {
page = await program.reLaunch(OPTIONS_PAGE_PATH)
await page.waitFor('view')
await test(page)
await test(OPTIONS_PAGE_PATH)
})
it('v-show composition API', async () => {
page = await program.reLaunch(COMPOSITION_PAGE_PATH)
await page.waitFor('view')
await test(page)
await test(COMPOSITION_PAGE_PATH)
})
})
\ No newline at end of file
......@@ -5,6 +5,8 @@ describe('component-lifecycle', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.includes('android')
const isIOS = platformInfo.includes('ios')
// TODO: harmony 暂不支持部分 API
const isHarmony = platformInfo.startsWith('harmony')
const isMP = platformInfo.startsWith('mp')
if(isMP) {
it('not support', async () => {
......@@ -58,30 +60,33 @@ describe('component-lifecycle', () => {
expect(lifeCycleNum).toBe(2)
await page.callMethod('pageSetLifeCycleNum', 0)
})
it('onPullDownRefresh', async () => {
await page.callMethod('pullDownRefresh')
await page.waitFor(2000)
lifeCycleNum = await page.callMethod('pageGetLifeCycleNum')
expect(lifeCycleNum).toBe(10)
await page.callMethod('pageSetLifeCycleNum', 0)
})
it('onPageScroll onReachBottom', async () => {
await program.pageScrollTo(2000)
// TODO: web 端组件内监听 onPageScroll onReachBottom 不触发
if (process.env.uniTestPlatformInfo.startsWith('android')) {
const isScrolled = await page.callMethod('getIsScrolled')
expect(isScrolled).toBe(true)
if (!isHarmony) {
// TODO: harmony 不支持 pullDownRefresh & pageScrollTo
it('onPullDownRefresh', async () => {
await page.callMethod('pullDownRefresh')
await page.waitFor(2000)
lifeCycleNum = await page.callMethod('pageGetLifeCycleNum')
expect(lifeCycleNum).toBe(10)
}
await page.callMethod('pageSetLifeCycleNum', 0)
})
await page.callMethod('pageSetLifeCycleNum', 0)
})
it('onPageScroll onReachBottom', async () => {
await program.pageScrollTo(2000)
// TODO: web 端组件内监听 onPageScroll onReachBottom 不触发
if (process.env.uniTestPlatformInfo.startsWith('android')) {
const isScrolled = await page.callMethod('getIsScrolled')
expect(isScrolled).toBe(true)
lifeCycleNum = await page.callMethod('pageGetLifeCycleNum')
expect(lifeCycleNum).toBe(10)
}
await page.callMethod('pageSetLifeCycleNum', 0)
})
}
it('onHide', async () => {
page = await program.navigateTo(HOME_PATH)
await page.waitFor('view')
lifeCycleNum = await page.callMethod('getLifeCycleNum')
// App 端页面离开返回不触发 keepAlive 组件 activated deactivated, 详见 https://issues.dcloud.net.cn/pages/issues/detail?id=7419
expect(lifeCycleNum).toBe(isIOS || isAndroid ? -10 : -11)
expect(lifeCycleNum).toBe((isIOS || isAndroid || isHarmony) ? -10 : -11)
page = await program.navigateBack()
await page.waitFor('view')
lifeCycleNum = await page.callMethod('pageGetLifeCycleNum')
......
jest.setTimeout(30000)
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
jest.setTimeout(30000)
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
// TODO: harmony 暂不支持部分 API
const isHarmony = platformInfo.includes('harmony')
const OPTIONS_PAGE_PATH = '/pages/lifecycle/page/page-options'
const COMPOSITION_PAGE_PATH = '/pages/lifecycle/page/page-composition'
......@@ -24,15 +26,18 @@ const testPageLifecycle = async (pagePath) => {
expect(lifeCycleNum).toBe(120)
await page.callMethod('pageSetLifeCycleNum', 0)
// onPullDownRefresh
await page.callMethod('pullDownRefresh')
await page.waitFor(1500)
lifeCycleNum = await page.callMethod('pageGetLifeCycleNum')
expect(lifeCycleNum).toBe(10)
await page.callMethod('pageSetLifeCycleNum', 0)
if(!isMP) {
if (!isHarmony) {
// TODO: harmony 不支持 pullDownRefresh
await page.callMethod('pullDownRefresh')
await page.waitFor(1500)
lifeCycleNum = await page.callMethod('pageGetLifeCycleNum')
expect(lifeCycleNum).toBe(10)
await page.callMethod('pageSetLifeCycleNum', 0)
}
if (!isMP && !isHarmony) {
// TODO: harmony 不支持 pageScrollTo
// onPageScroll onReachBottom
await program.pageScrollTo(2000)
await page.waitFor(1000)
......@@ -66,7 +71,7 @@ const testPageLifecycle = async (pagePath) => {
expect(lifeCycleNum).toBe(120)
page = await program.navigateBack()
await page.waitFor('view')
lifeCycleNum = await page.callMethod('getLifeCycleNum')
lifeCycleNum = await page.callMethod('getLifeCycleNum')
// 微信小程序不会触发onBackPress
expect(lifeCycleNum).toBe(isMP ? 20 : 10)
await page.callMethod('setLifeCycleNum', 0)
......
......@@ -59,41 +59,44 @@ describe('reactive', () => {
const updateArr1ReactiveBtn = await page.$('#update-arr1-reactive-btn')
await updateArr1ReactiveBtn.tap()
await page.waitFor(100)
expect(await arr1.text()).toBe(JSON.stringify([4, 5, 6]))
const arr2 = await page.$('#arr2')
expect(await arr2.text()).toBe('1')
const updateArr2ForEachEffectBtn = await page.$('#update-arr2-forEach-effect-btn')
expect(await arr1.text()).toBe(JSON.stringify([4, 5, 6]))
const arr2 = await page.$('#arr2')
expect(await arr2.text()).toBe('1')
const updateArr2ForEachEffectBtn = await page.$('#update-arr2-forEach-effect-btn')
await updateArr2ForEachEffectBtn.tap()
await page.waitFor(100)
expect(await arr2.text()).toBe('2')
const map2 = await page.$('#map2')
expect(await map2.text()).toBe('1')
const updateMap2ForEachEffectBtn = await page.$('#update-map2-forEach-effect-btn')
await page.waitFor(100)
expect(await arr2.text()).toBe('2')
const arr3 = await page.$('#arr3')
expect(await arr3.text()).toBe(JSON.stringify([1, 2, 3, 4, 5].reverse()))
const map2 = await page.$('#map2')
expect(await map2.text()).toBe('1')
const updateMap2ForEachEffectBtn = await page.$('#update-map2-forEach-effect-btn')
await updateMap2ForEachEffectBtn.tap()
await page.waitFor(100)
expect(await map2.text()).toBe('2')
const map3 = await page.$('#map3')
expect(await map3.text()).toBe('1')
const updateMap3ForOfEffectBtn = await page.$('#update-map3-forOf-effect-btn')
await page.waitFor(100)
expect(await map2.text()).toBe('2')
const map3 = await page.$('#map3')
expect(await map3.text()).toBe('1')
const updateMap3ForOfEffectBtn = await page.$('#update-map3-forOf-effect-btn')
await updateMap3ForOfEffectBtn.tap()
await page.waitFor(100)
expect(await map3.text()).toBe('2')
const set2 = await page.$('#set2')
expect(await set2.text()).toBe('1')
const updateSet2ForEachEffectBtn = await page.$('#update-set2-forEach-effect-btn')
await page.waitFor(100)
expect(await map3.text()).toBe('2')
const set2 = await page.$('#set2')
expect(await set2.text()).toBe('1')
const updateSet2ForEachEffectBtn = await page.$('#update-set2-forEach-effect-btn')
await updateSet2ForEachEffectBtn.tap()
await page.waitFor(100)
expect(await set2.text()).toBe('2')
const set3 = await page.$('#set3')
expect(await set3.text()).toBe('1')
const updateSet3ForOfEffectBtn = await page.$('#update-set3-forOf-effect-btn')
await page.waitFor(100)
expect(await set2.text()).toBe('2')
const set3 = await page.$('#set3')
expect(await set3.text()).toBe('1')
const updateSet3ForOfEffectBtn = await page.$('#update-set3-forOf-effect-btn')
await updateSet3ForOfEffectBtn.tap()
await page.waitFor(100)
await page.waitFor(100)
expect(await set3.text()).toBe('2')
})
})
\ No newline at end of file
......@@ -32,21 +32,25 @@
<text>arr2ForEachEffectCount:</text>
<text id="arr2">{{ arr2ForEachEffectCount }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>arr3(reverse):</text>
<text id="arr3">{{ JSON.stringify(arr3) }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>map2ForEachEffectCount:</text>
<text id="map2">{{ map2ForEachEffectCount }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>map3ForOfEffectCount:</text>
<text id="map3">{{ map3ForOfEffectCount }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>set2ForEachEffectCount:</text>
<text id="set2">{{ set2ForEachEffectCount }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>set3ForOfEffectCount:</text>
<text id="set3">{{ set3ForOfEffectCount }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>map3ForOfEffectCount:</text>
<text id="map3">{{ map3ForOfEffectCount }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>set2ForEachEffectCount:</text>
<text id="set2">{{ set2ForEachEffectCount }}</text>
</view>
<view class="flex justify-between flex-row mb-10">
<text>set3ForOfEffectCount:</text>
<text id="set3">{{ set3ForOfEffectCount }}</text>
</view>
<button class='mb-10' id="update-count-btn" @click="updateCount">update count</button>
<button class='mb-10' id="update-obj-str-btn" @click="updateObjStr">update obj.str</button>
......@@ -56,9 +60,9 @@
<button class='mb-10' id="update-arr1-btn" @click="updateArr1(false)">update arr1 without reactive</button>
<button class='mb-10' id="update-arr1-reactive-btn" @click="updateArr1(true)">update arr1 with reactive</button>
<button class='mb-10' id="update-arr2-forEach-effect-btn" @click="updateArr2()">update arr2</button>
<button class='mb-10' id="update-map2-forEach-effect-btn" @click="updateMap2()">update map2 for each</button>
<button class='mb-10' id="update-map3-forOf-effect-btn" @click="updateMap3()">update map3 for of</button>
<button class='mb-10' id="update-set2-forEach-effect-btn" @click="updateSet2()">update set2 for each</button>
<button class='mb-10' id="update-map2-forEach-effect-btn" @click="updateMap2()">update map2 for each</button>
<button class='mb-10' id="update-map3-forOf-effect-btn" @click="updateMap3()">update map3 for of</button>
<button class='mb-10' id="update-set2-forEach-effect-btn" @click="updateSet2()">update set2 for each</button>
<button class='mb-10' id="update-set3-forOf-effect-btn" @click="updateSet3()">update set3 for of</button>
</scroll-view>
</template>
......@@ -125,6 +129,8 @@
function updateArr2() {
arr2.push(Date.now())
}
var arr3 = reactive([1, 2, 3, 4, 5]).reverse()
const map2 = reactive(new Map<string, number>([["a", 1]]))
const map2ForEachEffectCount = ref(0)
......@@ -136,41 +142,41 @@
})
function updateMap2() {
map2.set("c-" + Date.now(), Date.now())
}
const map3 = reactive(new Map<string, number>([["a", 1]]))
const map3ForOfEffectCount = ref(0)
watchEffect(() => {
map3ForOfEffectCount.value++
for(const item of map3){
console.log("map3",item)
}
})
function updateMap3() {
map3.set("c-" + Date.now(), Date.now())
}
const set2 = reactive(new Set<number>([1]))
const set2ForEachEffectCount = ref(0)
watchEffect(() => {
set2ForEachEffectCount.value++
set2.forEach((item : number) => {
console.log('set2', item)
})
})
function updateSet2() {
set2.add(Date.now())
}
const set3 = reactive(new Set<number>([1]))
const set3ForOfEffectCount = ref(0)
watchEffect(() => {
set3ForOfEffectCount.value++
for(const item of set3){
console.log("set3",item)
}
})
function updateSet3() {
set3.add(Date.now())
}
const map3 = reactive(new Map<string, number>([["a", 1]]))
const map3ForOfEffectCount = ref(0)
watchEffect(() => {
map3ForOfEffectCount.value++
for(const item of map3){
console.log("map3",item)
}
})
function updateMap3() {
map3.set("c-" + Date.now(), Date.now())
}
const set2 = reactive(new Set<number>([1]))
const set2ForEachEffectCount = ref(0)
watchEffect(() => {
set2ForEachEffectCount.value++
set2.forEach((item : number) => {
console.log('set2', item)
})
})
function updateSet2() {
set2.add(Date.now())
}
const set3 = reactive(new Set<number>([1]))
const set3ForOfEffectCount = ref(0)
watchEffect(() => {
set3ForOfEffectCount.value++
for(const item of set3){
console.log("set3",item)
}
})
function updateSet3() {
set3.add(Date.now())
}
</script>
\ No newline at end of file
const PAGE_PATH = '/pages/reactivity/core/watch-effect/watch-effect'
const platformInfo = process.env.uniTestPlatformInfo.toLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
describe('watchEffect', () => {
if(isMP) {
// 微信小程序支持此特性,但是示例内部使用了较多的dom api无法兼容微信小程序
it('not support', async () => {
expect(1).toBe(1)
})
return
}
const isMP = platformInfo.startsWith('mp')
// TODO: harmony 进入页面崩溃
const isHarmony = platformInfo.includes('harmony')
describe('watchEffect', () => {
if(isMP || isHarmony) {
// 微信小程序支持此特性,但是示例内部使用了较多的dom api无法兼容微信小程序
it('not support', async () => {
expect(1).toBe(1)
})
return
}
let page = null
beforeAll(async () => {
......@@ -32,7 +34,7 @@ describe('watchEffect', () => {
// track
const watchCountTrackNum = await page.$('#watch-count-track-num')
if (isAndroid) {
expect(await watchCountTrackNum.text()).toBe('3')
expect(await watchCountTrackNum.text()).toBe('3')
} else {
expect(await watchCountTrackNum.text()).toBe('6')
}
......@@ -158,4 +160,4 @@ describe('watchEffect', () => {
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res')
expect(await watchCountAndObjNumRes.text()).toBe('count: 3, obj.num: 1')
})
})
})
......@@ -4,17 +4,19 @@ const platformInfo = process.env.uniTestPlatformInfo.toLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIOS = platformInfo.startsWith('ios')
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
describe('watchPostEffect', () => {
if(isMP) {
// 微信小程序支持此特性,但是示例内部使用了较多的dom api无法兼容微信小程序
it('not support', async () => {
expect(1).toBe(1)
})
return
}
const isMP = platformInfo.startsWith('mp')
// TODO: harmony 进入页面崩溃
const isHarmony = platformInfo.includes('harmony')
describe('watchPostEffect', () => {
if(isMP || isHarmony) {
// 微信小程序支持此特性,但是示例内部使用了较多的dom api无法兼容微信小程序
it('not support', async () => {
expect(1).toBe(1)
})
return
}
let page = null
......@@ -146,4 +148,4 @@ describe('watchPostEffect', () => {
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res')
expect(await watchCountAndObjNumRes.text()).toBe('count: 3, obj.num: 1')
})
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册