提交 a889ec1e 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test: 调整测试例兼容 web 端

上级 a9bbe02f
...@@ -14,6 +14,6 @@ describe('$forceUpdate', () => { ...@@ -14,6 +14,6 @@ describe('$forceUpdate', () => {
await triggerForceUpdateBtn.tap() await triggerForceUpdateBtn.tap()
const timeText2 = (await timeEl.text()).replace('Date.now(): ', '') const timeText2 = (await timeEl.text()).replace('Date.now(): ', '')
expect(parseInt(timeText2)).toBeGreaterThan(parseInt(timeText1)) expect(parseInt(timeText2)).toBeGreaterThanOrEqual(parseInt(timeText1))
}) })
}) })
...@@ -15,9 +15,9 @@ describe('$props', () => { ...@@ -15,9 +15,9 @@ describe('$props', () => {
const arrayLiteralBool = await page.$('#array-literal-bool') const arrayLiteralBool = await page.$('#array-literal-bool')
expect(await arrayLiteralBool.text()).toBe('true') expect(await arrayLiteralBool.text()).toBe('true')
const arrayLiteralObj = await page.$('#array-literal-obj') const arrayLiteralObj = await page.$('#array-literal-obj')
expect((await arrayLiteralObj.text()).replaceAll('\n', '').replaceAll(' ', '')).toBe('{"count":1}') expect((await arrayLiteralObj.text()).replaceAll(' ', '')).toBe('{"count":1}')
const arrayLiteralArr = await page.$('#array-literal-arr') const arrayLiteralArr = await page.$('#array-literal-arr')
expect((await arrayLiteralArr.text()).replaceAll('\n', '')).toBe('[1,2,3]') expect(await arrayLiteralArr.text()).toBe('[1,2,3]')
const string = await page.$('.string') const string = await page.$('.string')
const number = await page.$('.number') const number = await page.$('.number')
...@@ -32,8 +32,8 @@ describe('$props', () => { ...@@ -32,8 +32,8 @@ describe('$props', () => {
expect(await object.text()).toBe('1') expect(await object.text()).toBe('1')
const checkTypeArr = await page.$('#check-type-arr') const checkTypeArr = await page.$('#check-type-arr')
expect((await checkTypeArr.text()).replaceAll('\n', '')).toBe('arr: ["a","b","c"]') expect(await checkTypeArr.text()).toBe('arr: ["a","b","c"]')
const fooArr = await page.$('#foo-arr') const fooArr = await page.$('#foo-arr')
expect((await fooArr.text()).replaceAll('\n', '')).toBe('arr: [1,2,3]') expect(await fooArr.text()).toBe('arr: [1,2,3]')
}) })
}) })
...@@ -14,6 +14,6 @@ describe('defineSlots', () => { ...@@ -14,6 +14,6 @@ describe('defineSlots', () => {
expect(await slotContent.text()).toBe('default slot num: 0') expect(await slotContent.text()).toBe('default slot num: 0')
const slotFooter = await page.$('#slot-footer') const slotFooter = await page.$('#slot-footer')
expect((await slotFooter.text()).replaceAll('\n', '')).toBe('footer slot arr: ["a","b","c"]') expect(await slotFooter.text()).toBe('footer slot arr: ["a","b","c"]')
}) })
}) })
\ No newline at end of file
...@@ -15,11 +15,11 @@ describe('provide-inject-hasInjectionContext', () => { ...@@ -15,11 +15,11 @@ describe('provide-inject-hasInjectionContext', () => {
expect(await num.text()).toBe('num: 0') expect(await num.text()).toBe('num: 0')
const obj = await page.$('.obj') const obj = await page.$('.obj')
expect(await obj.text()).toBe(isWeb ? 'obj: {\n"a": 1\n}' : 'obj: {"a":1}') expect(await obj.text()).toBe(isWeb ? 'obj: {"a": 1}' : 'obj: {"a":1}')
const arr = await page.$('.arr') const arr = await page.$('.arr')
expect(await arr.text()).toBe(isWeb ? 'arr: [\n1,\n2,\n3\n]' : 'arr: [1,2,3]') expect(await arr.text()).toBe('arr: [1,2,3]')
const fn = await page.$('.fn') const fn = await page.$('.fn')
expect(await fn.text()).toBe('fn: hello') expect(await fn.text()).toBe('fn: hello')
......
...@@ -2,13 +2,6 @@ const PAGE_PATH = '/pages/composition-api/lifecycle/component-lifecycle/componen ...@@ -2,13 +2,6 @@ const PAGE_PATH = '/pages/composition-api/lifecycle/component-lifecycle/componen
const HOME_PATH = '/pages/tab-bar/options-api' const HOME_PATH = '/pages/tab-bar/options-api'
describe('component-lifecycle', () => { describe('component-lifecycle', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) {
// TODO: 自动化测试暂不能调用web端setup内defineExpose导出的方法,待自动化测试兼容后开放此测试例
it('web', async () => {
expect(1).toBe(1)
})
return
}
let page let page
let lifeCycleNum let lifeCycleNum
beforeAll(async () => { beforeAll(async () => {
......
...@@ -4,14 +4,14 @@ const INTER_PAGE_PATH = '/pages/app-instance/index/index' ...@@ -4,14 +4,14 @@ const INTER_PAGE_PATH = '/pages/app-instance/index/index'
let page let page
let lifeCycleNum let lifeCycleNum
describe('page-lifecycle', () => { describe('page-lifecycle', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { if (process.env.uniTestPlatformInfo.startsWith('web')) {
// TODO: 自动化测试暂不能调用web端setup内defineExpose导出的方法,待自动化测试兼容后开放此测试例 // TODO: onPageShow onPageHide 别名暂不支持
it('web', async () => { it('web', async () => {
expect(1).toBe(1) expect(1).toBe(1)
}) })
return return
} }
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(HOME_PATH) page = await program.reLaunch(HOME_PATH)
await page.waitFor(700) await page.waitFor(700)
...@@ -28,7 +28,7 @@ describe('page-lifecycle', () => { ...@@ -28,7 +28,7 @@ describe('page-lifecycle', () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(700) await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(130) expect(lifeCycleNum).toBe(120)
await page.callMethod('pageSetlifeCycleNum', 0) await page.callMethod('pageSetlifeCycleNum', 0)
}) })
it('onPullDownRefresh', async () => { it('onPullDownRefresh', async () => {
...@@ -67,7 +67,7 @@ describe('page-lifecycle', () => { ...@@ -67,7 +67,7 @@ describe('page-lifecycle', () => {
page = await program.navigateTo(PAGE_PATH) page = await program.navigateTo(PAGE_PATH)
await page.waitFor(700) await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(130) expect(lifeCycleNum).toBe(120)
page = await program.navigateBack() page = await program.navigateBack()
await page.waitFor('view') await page.waitFor('view')
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
......
...@@ -13,16 +13,16 @@ describe('computed', () => { ...@@ -13,16 +13,16 @@ describe('computed', () => {
expect(await doubleCount.text()).toBe('computed double count: 0') expect(await doubleCount.text()).toBe('computed double count: 0')
const objArr = await page.$('#obj-arr') const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [1,2,3]') expect(await objArr.text()).toBe('obj.arr: [1,2,3]')
const objArrLen = await page.$('#obj-arr-len') const objArrLen = await page.$('#obj-arr-len')
expect(await objArrLen.text()).toBe('computed obj.arr.length: 3') expect(await objArrLen.text()).toBe('computed obj.arr.length: 3')
const updateBtn = await page.$('.update-btn') const updateBtn = await page.$('#update-btn')
await updateBtn.tap() await updateBtn.tap()
expect(await count.text()).toBe('count: 1') expect(await count.text()).toBe('count: 1')
expect(await doubleCount.text()).toBe('computed double count: 2') expect(await doubleCount.text()).toBe('computed double count: 2')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [1,2,3,4]') expect(await objArr.text()).toBe('obj.arr: [1,2,3,4]')
expect(await objArrLen.text()).toBe('computed obj.arr.length: 4') expect(await objArrLen.text()).toBe('computed obj.arr.length: 4')
}) })
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<text id="double-count" class="uni-common-mb">computed double count: {{ doubleCount }}</text> <text id="double-count" class="uni-common-mb">computed double count: {{ doubleCount }}</text>
<text id="obj-arr" class="uni-common-mb">obj.arr: {{ obj.arr }}</text> <text id="obj-arr" class="uni-common-mb">obj.arr: {{ obj.arr }}</text>
<text id="obj-arr-len" class="uni-common-mb">computed obj.arr.length: {{ objArrLen }}</text> <text id="obj-arr-len" class="uni-common-mb">computed obj.arr.length: {{ objArrLen }}</text>
<button class="update-btn" @click="update">update</button> <button id="update-btn" @click="update">update</button>
</view> </view>
</template> </template>
......
...@@ -17,7 +17,7 @@ describe('reactive', () => { ...@@ -17,7 +17,7 @@ describe('reactive', () => {
expect(await objNum.text()).toBe('obj.num: 0') expect(await objNum.text()).toBe('obj.num: 0')
const objArr = await page.$('#obj-arr') const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: ["a","b","c"]') expect(await objArr.text()).toBe('obj.arr: ["a","b","c"]')
const updateBtn = await page.$('.update-btn') const updateBtn = await page.$('.update-btn')
await updateBtn.tap() await updateBtn.tap()
...@@ -25,6 +25,6 @@ describe('reactive', () => { ...@@ -25,6 +25,6 @@ describe('reactive', () => {
expect(await count.text()).toBe('count: 2') expect(await count.text()).toBe('count: 2')
expect(await objStr.text()).toBe('obj.str: new str') expect(await objStr.text()).toBe('obj.str: new str')
expect(await objNum.text()).toBe('obj.num: 2') expect(await objNum.text()).toBe('obj.num: 2')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: ["a","b","c","d"]') expect(await objArr.text()).toBe('obj.arr: ["a","b","c","d"]')
}) })
}) })
\ No newline at end of file
const PAGE_PATH = '/pages/composition-api/reactivity/readonly/readonly' const PAGE_PATH = '/pages/composition-api/reactivity/readonly/readonly'
describe('ref', () => { describe('ref', () => {
const isWeb = process.env.uniTestPlatformInfo.startsWith('web')
let page = null let page = null
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
...@@ -13,33 +12,33 @@ describe('ref', () => { ...@@ -13,33 +12,33 @@ describe('ref', () => {
const dataNum = await page.$('#data-num') const dataNum = await page.$('#data-num')
expect(await dataNum.text()).toBe('data.num: 0') expect(await dataNum.text()).toBe('data.num: 0')
const dataArr = await page.$('#data-arr') const dataArr = await page.$('#data-arr')
expect(await dataArr.text()).toBe(isWeb ? 'data.arr: [\n"a",\n"b",\n"c"\n]' : 'data.arr: ["a","b","c"]') expect(await dataArr.text()).toBe('data.arr: ["a","b","c"]')
const readonlyDataStr = await page.$('#readonly-data-str') const readonlyDataStr = await page.$('#readonly-data-str')
expect(await readonlyDataStr.text()).toBe('readonly data.str: default str') expect(await readonlyDataStr.text()).toBe('readonly data.str: default str')
const readonlyDataNum = await page.$('#readonly-data-num') const readonlyDataNum = await page.$('#readonly-data-num')
expect(await readonlyDataNum.text()).toBe('readonly data.num: 0') expect(await readonlyDataNum.text()).toBe('readonly data.num: 0')
const readonlyDataArr = await page.$('#readonly-data-arr') const readonlyDataArr = await page.$('#readonly-data-arr')
expect(await readonlyDataArr.text()).toBe(isWeb ? 'readonly data.arr: [\n"a",\n"b",\n"c"\n]' : 'readonly data.arr: ["a","b","c"]') expect(await readonlyDataArr.text()).toBe('readonly data.arr: ["a","b","c"]')
const updateDataBtn = await page.$('#update-data-btn') const updateDataBtn = await page.$('#update-data-btn')
await updateDataBtn.tap() await updateDataBtn.tap()
expect(await dataStr.text()).toBe('data.str: new str') expect(await dataStr.text()).toBe('data.str: new str')
expect(await dataNum.text()).toBe('data.num: 1') expect(await dataNum.text()).toBe('data.num: 1')
expect(await dataArr.text()).toBe(isWeb ? 'data.arr: [\n"a",\n"b",\n"c",\n"d"\n]' : 'data.arr: ["a","b","c","d"]') expect(await dataArr.text()).toBe('data.arr: ["a","b","c","d"]')
expect(await readonlyDataStr.text()).toBe('readonly data.str: new str') expect(await readonlyDataStr.text()).toBe('readonly data.str: new str')
expect(await readonlyDataNum.text()).toBe('readonly data.num: 1') expect(await readonlyDataNum.text()).toBe('readonly data.num: 1')
expect(await readonlyDataArr.text()).toBe(isWeb ? 'readonly data.arr: [\n"a",\n"b",\n"c",\n"d"\n]' : 'readonly data.arr: ["a","b","c","d"]') expect(await readonlyDataArr.text()).toBe('readonly data.arr: ["a","b","c","d"]')
const updateReadonlyDataBtn = await page.$('#update-readonly-data-btn') const updateReadonlyDataBtn = await page.$('#update-readonly-data-btn')
await updateReadonlyDataBtn.tap() await updateReadonlyDataBtn.tap()
expect(await dataStr.text()).toBe('data.str: new str') expect(await dataStr.text()).toBe('data.str: new str')
expect(await dataNum.text()).toBe('data.num: 1') expect(await dataNum.text()).toBe('data.num: 1')
expect(await dataArr.text()).toBe(isWeb ? 'data.arr: [\n"a",\n"b",\n"c",\n"d"\n]' : 'data.arr: ["a","b","c","d"]') expect(await dataArr.text()).toBe('data.arr: ["a","b","c","d"]')
expect(await readonlyDataStr.text()).toBe('readonly data.str: new str') expect(await readonlyDataStr.text()).toBe('readonly data.str: new str')
expect(await readonlyDataNum.text()).toBe('readonly data.num: 1') expect(await readonlyDataNum.text()).toBe('readonly data.num: 1')
expect(await readonlyDataArr.text()).toBe(isWeb ? 'readonly data.arr: [\n"a",\n"b",\n"c",\n"d"\n]' : 'readonly data.arr: ["a","b","c","d"]') expect(await readonlyDataArr.text()).toBe('readonly data.arr: ["a","b","c","d"]')
}) })
}) })
\ No newline at end of file
...@@ -76,7 +76,7 @@ describe('watchEffect', () => { ...@@ -76,7 +76,7 @@ describe('watchEffect', () => {
const objBool = await page.$('#obj-bool') const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false') expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr') const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0]') expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res') const watchObjRes = await page.$('#watch-obj-res')
if (process.env.uniTestPlatformInfo.startsWith('android')) { if (process.env.uniTestPlatformInfo.startsWith('android')) {
...@@ -104,7 +104,7 @@ describe('watchEffect', () => { ...@@ -104,7 +104,7 @@ describe('watchEffect', () => {
expect(await objStr.text()).toBe('obj.str: num: 1') expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1') expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true') expect(await objBool.text()).toBe('obj.bool: true')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0,1]') expect(await objArr.text()).toBe('obj.arr: [0,1]')
if (process.env.uniTestPlatformInfo.startsWith('android')) { if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjRes.text()).toBe( expect(await watchObjRes.text()).toBe(
......
...@@ -78,7 +78,7 @@ describe('watchPostEffect', () => { ...@@ -78,7 +78,7 @@ describe('watchPostEffect', () => {
const objBool = await page.$('#obj-bool') const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false') expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr') const objArr = await page.$('#obj-arr')
expect(await objArr.text()).toBe(isWeb ? 'obj.arr: [\n0\n]' : 'obj.arr: [0]') expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res') const watchObjRes = await page.$('#watch-obj-res')
// TODO web端和安卓端JSON.stringify对属性的排序不一致 // TODO web端和安卓端JSON.stringify对属性的排序不一致
...@@ -99,16 +99,16 @@ describe('watchPostEffect', () => { ...@@ -99,16 +99,16 @@ describe('watchPostEffect', () => {
expect(await objStr.text()).toBe('obj.str: num: 1') expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1') expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true') expect(await objBool.text()).toBe('obj.bool: true')
expect(await objArr.text()).toBe(isWeb ? 'obj.arr: [\n0,\n1\n]' : 'obj.arr: [0,1]') expect(await objArr.text()).toBe('obj.arr: [0,1]')
expect(await watchObjRes.text()).toBe( expect(await watchObjRes.text()).toBe(
isWeb ? isWeb ?
'watch obj result: obj: {"num":0,"str":"num: 0","bool":false,"arr":[0]}' : 'watch obj result: obj: {"num":1,"str":"num: 1","bool":true,"arr":[0,1]}' :
'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}' 'watch obj result: obj: {"arr":[0],"bool":false,"num":0,"str":"num: 0"}'
) )
expect(await watchObjStrRes.text()).toBe( expect(await watchObjStrRes.text()).toBe(
'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 1') 'watch obj.str result: str: num: 1, obj.str ref text: obj.str: num: 1')
expect(await watchObjArrRes.text()).toBe(isWeb ? 'watch obj.arr result: arr: [\n0,\n1\n]' : expect(await watchObjArrRes.text()).toBe(
'watch obj.arr result: arr: [0,1]') 'watch obj.arr result: arr: [0,1]')
const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res') const watchCountAndObjNumRes = await page.$('#watch-count-obj-num-res')
......
...@@ -76,7 +76,7 @@ describe('watchSyncEffect', () => { ...@@ -76,7 +76,7 @@ describe('watchSyncEffect', () => {
const objBool = await page.$('#obj-bool') const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false') expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr') const objArr = await page.$('#obj-arr')
expect(await objArr.text()).toBe(isWeb ? 'obj.arr: [\n0\n]' : 'obj.arr: [0]') expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res') const watchObjRes = await page.$('#watch-obj-res')
expect(await watchObjRes.text()).toBe( expect(await watchObjRes.text()).toBe(
...@@ -96,7 +96,7 @@ describe('watchSyncEffect', () => { ...@@ -96,7 +96,7 @@ describe('watchSyncEffect', () => {
expect(await objStr.text()).toBe('obj.str: num: 1') expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1') expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true') expect(await objBool.text()).toBe('obj.bool: true')
expect(await objArr.text()).toBe(isWeb ? 'obj.arr: [\n0,\n1\n]' : 'obj.arr: [0,1]') expect(await objArr.text()).toBe('obj.arr: [0,1]')
expect(await watchObjRes.text()).toBe( expect(await watchObjRes.text()).toBe(
isWeb ? isWeb ?
......
...@@ -81,7 +81,7 @@ describe('watch', () => { ...@@ -81,7 +81,7 @@ describe('watch', () => {
const objBool = await page.$('#obj-bool') const objBool = await page.$('#obj-bool')
expect(await objBool.text()).toBe('obj.bool: false') expect(await objBool.text()).toBe('obj.bool: false')
const objArr = await page.$('#obj-arr') const objArr = await page.$('#obj-arr')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0]') expect(await objArr.text()).toBe('obj.arr: [0]')
const watchObjRes = await page.$('#watch-obj-res') const watchObjRes = await page.$('#watch-obj-res')
if (process.env.uniTestPlatformInfo.startsWith('android')) { if (process.env.uniTestPlatformInfo.startsWith('android')) {
...@@ -107,7 +107,7 @@ describe('watch', () => { ...@@ -107,7 +107,7 @@ describe('watch', () => {
expect(await objStr.text()).toBe('obj.str: num: 1') expect(await objStr.text()).toBe('obj.str: num: 1')
expect(await objNum.text()).toBe('obj.num: 1') expect(await objNum.text()).toBe('obj.num: 1')
expect(await objBool.text()).toBe('obj.bool: true') expect(await objBool.text()).toBe('obj.bool: true')
expect((await objArr.text()).replaceAll('\n', '')).toBe('obj.arr: [0,1]') expect(await objArr.text()).toBe('obj.arr: [0,1]')
if (process.env.uniTestPlatformInfo.startsWith('android')) { if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(await watchObjRes.text()).toBe( expect(await watchObjRes.text()).toBe(
......
...@@ -51,21 +51,21 @@ describe('函数方式创建 provide', () => { ...@@ -51,21 +51,21 @@ describe('函数方式创建 provide', () => {
const providePageArrEl = await page.$('.provide-page-arr') const providePageArrEl = await page.$('.provide-page-arr')
const providePageArrText = await providePageArrEl.text() const providePageArrText = await providePageArrEl.text()
expect(providePageArrText).toBe( expect(providePageArrText).toBe(
isWeb ? 'providePageArr: [\n"函数方式定义 provide page arr"\n]' : 'providePageArr: ["函数方式定义 provide page arr"]' 'providePageArr: ["函数方式定义 provide page arr"]'
) )
}) })
it('map', async () => { it('map', async () => {
const providePageMapEl = await page.$('.provide-page-map') const providePageMapEl = await page.$('.provide-page-map')
const providePageMapText = await providePageMapEl.text() const providePageMapText = await providePageMapEl.text()
expect(providePageMapText).toBe( expect(providePageMapText).toBe(
isWeb ? 'providePageMap: {\n"key": "函数方式定义 provide page map"\n}' : 'providePageMap: {"key":"函数方式定义 provide page map"}' isWeb ? 'providePageMap: {"key": "函数方式定义 provide page map"}' : 'providePageMap: {"key":"函数方式定义 provide page map"}'
) )
}) })
it('set', async () => { it('set', async () => {
const providePageSetEl = await page.$('.provide-page-set') const providePageSetEl = await page.$('.provide-page-set')
const providePageSetText = await providePageSetEl.text() const providePageSetText = await providePageSetEl.text()
expect(providePageSetText).toBe( expect(providePageSetText).toBe(
isWeb ? 'providePageSet: [\n"函数方式定义 provide page set"\n]' : 'providePageSet: ["函数方式定义 provide page set"]' 'providePageSet: ["函数方式定义 provide page set"]'
) )
}) })
}) })
...@@ -51,21 +51,21 @@ describe('字面量方式创建 provide', () => { ...@@ -51,21 +51,21 @@ describe('字面量方式创建 provide', () => {
const providePageArrEl = await page.$('.provide-page-arr') const providePageArrEl = await page.$('.provide-page-arr')
const providePageArrText = await providePageArrEl.text() const providePageArrText = await providePageArrEl.text()
expect(providePageArrText).toBe( expect(providePageArrText).toBe(
isWeb ? 'providePageArr: [\n"字面量方式定义 provide page arr"\n]' : 'providePageArr: ["字面量方式定义 provide page arr"]' 'providePageArr: ["字面量方式定义 provide page arr"]'
) )
}) })
it('map', async () => { it('map', async () => {
const providePageMapEl = await page.$('.provide-page-map') const providePageMapEl = await page.$('.provide-page-map')
const providePageMapText = await providePageMapEl.text() const providePageMapText = await providePageMapEl.text()
expect(providePageMapText).toBe( expect(providePageMapText).toBe(
isWeb ? 'providePageMap: {\n"key": "字面量方式定义 provide page map"\n}' : 'providePageMap: {"key":"字面量方式定义 provide page map"}' isWeb ? 'providePageMap: {"key": "字面量方式定义 provide page map"}' : 'providePageMap: {"key":"字面量方式定义 provide page map"}'
) )
}) })
it('set', async () => { it('set', async () => {
const providePageSetEl = await page.$('.provide-page-set') const providePageSetEl = await page.$('.provide-page-set')
const providePageSetText = await providePageSetEl.text() const providePageSetText = await providePageSetEl.text()
expect(providePageSetText).toBe( expect(providePageSetText).toBe(
isWeb ? 'providePageSet: [\n"字面量方式定义 provide page set"\n]' : 'providePageSet: ["字面量方式定义 provide page set"]' 'providePageSet: ["字面量方式定义 provide page set"]'
) )
}) })
it('string default value', async () => { it('string default value', async () => {
...@@ -97,4 +97,4 @@ describe('字面量方式创建 provide', () => { ...@@ -97,4 +97,4 @@ describe('字面量方式创建 provide', () => {
'testInjectObjectDefaultValue.content: test inject object default value content' 'testInjectObjectDefaultValue.content: test inject object default value content'
) )
}) })
}) })
\ No newline at end of file
const PAGE_PATH = '/pages/directive/v-model/v-model' const PAGE_PATH = '/pages/directive/v-model/v-model'
describe('v-model', () => { describe('v-model', () => {
if (process.env.uniTestPlatformInfo.startsWith('web')) { let page
// TODO: web 自动化测试InputElement input方法报错 beforeAll(async () => {
it('web', async () => { page = await program.reLaunch(PAGE_PATH)
expect(1).toBe(1) await page.waitFor(500)
}) })
return
} it('input', async () => {
let page const value = Date.now() + ''
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) // TODO: 自动化测试web端存在问题
await page.waitFor(500) // 1. 直接获取 input 由于 web 端 input 为框架封装的自定义组件,所以被自动化测试框架识别为组定义组件,而不是 input element
}) // 2. 通过 class 获取标准 input element,自动化测试框架 isValidEl 限制只允许获取 uni element
if (process.env.uniTestPlatformInfo.startsWith('android')) {
it('input', async () => { const inputElement = await page.$('.input')
const value = Date.now() + '' await inputElement.input(value)
const inputValueElement = await page.$('.input-value')
const inputElement = await page.$('.input') expect(await inputValueElement.text()).toBe(value)
await inputElement.input(value) }
})
const inputValueElement = await page.$('.input-value')
expect(await inputValueElement.text()).toBe(value)
})
}) })
\ No newline at end of file
const PAGE_PATH = '/pages/lifecycle/page/page' const PAGE_PATH = '/pages/lifecycle/page/page'
const HOME_PATH = '/pages/tab-bar/options-api' const HOME_PATH = '/pages/tab-bar/options-api'
const INTER_PAGE_PATH = '/pages/app-instance/index/index' const INTER_PAGE_PATH = '/pages/app-instance/index/index'
let page let page
let lifeCycleNum let lifeCycleNum
describe('app-lifecycle', () => { describe('app-lifecycle', () => {
it('onLaunch onShow', async () => { it('onLaunch onShow', async () => {
page = await program.reLaunch(HOME_PATH) page = await program.reLaunch(HOME_PATH)
await page.waitFor(700) await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(1100) expect(lifeCycleNum).toBe(1100)
}) })
it('onLastPageBackPress', async () => { it('onLastPageBackPress', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) { if (process.env.uniTestPlatformInfo.startsWith('android')) {
page = await program.navigateBack() page = await program.navigateBack()
await page.waitFor(700) await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(100) expect(lifeCycleNum).toBe(100)
} }
await page.callMethod('setLifeCycleNum', 0) await page.callMethod('setLifeCycleNum', 0)
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(0) expect(lifeCycleNum).toBe(0)
}) })
}) })
describe('page-lifecycle', () => { describe('page-lifecycle', () => {
afterAll(async () => { afterAll(async () => {
const resetLifecycleNum = 1100 const resetLifecycleNum = 1100
await page.callMethod('setLifeCycleNum', resetLifecycleNum) await page.callMethod('setLifeCycleNum', resetLifecycleNum)
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(resetLifecycleNum) expect(lifeCycleNum).toBe(resetLifecycleNum)
}) })
it('onLoad onShow onReady onResize', async () => { it('onLoad onShow onReady onResize', async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor(700) await page.waitFor(700)
lifeCycleNum = await page.callMethod('getLifeCycleNum') lifeCycleNum = await page.callMethod('getLifeCycleNum')
// TODO 安卓端调整页面加载不触发onResize后调整此测试例 expect(lifeCycleNum).toBe(120)
if (process.env.uniTestPlatformInfo.startsWith('android')) { await page.callMethod('setLifeCycleNum', 0)
expect(lifeCycleNum).toBe(130) })
} else if(process.env.uniTestPlatformInfo.startsWith('web')){ it('onPullDownRefresh', async () => {
expect(lifeCycleNum).toBe(120) await page.callMethod('pullDownRefresh')
} await page.waitFor(1500)
await page.callMethod('setLifeCycleNum', 0) lifeCycleNum = await page.callMethod('getLifeCycleNum')
}) expect(lifeCycleNum).toBe(10)
it('onPullDownRefresh', async () => { await page.callMethod('setLifeCycleNum', 0)
await page.callMethod('pullDownRefresh') })
await page.waitFor(1500) it('onPageScroll onReachBottom', async () => {
lifeCycleNum = await page.callMethod('getLifeCycleNum') await program.pageScrollTo(2000)
expect(lifeCycleNum).toBe(10) const data = await page.data()
await page.callMethod('setLifeCycleNum', 0) expect(data.isScrolled).toBe(true)
}) lifeCycleNum = await page.callMethod('getLifeCycleNum')
it('onPageScroll onReachBottom', async () => { expect(lifeCycleNum).toBe(10)
await program.pageScrollTo(2000) await page.callMethod('setLifeCycleNum', 0)
const data = await page.data() })
expect(data.isScrolled).toBe(true) it('onHide', async () => {
lifeCycleNum = await page.callMethod('getLifeCycleNum') page = await program.navigateTo(INTER_PAGE_PATH)
expect(lifeCycleNum).toBe(10) await page.waitFor('view')
await page.callMethod('setLifeCycleNum', 0) lifeCycleNum = await page.callMethod('getLifeCycleNum')
}) expect(lifeCycleNum).toBe(-10)
it('onHide', async () => { page = await program.navigateBack()
page = await program.navigateTo(INTER_PAGE_PATH) await page.waitFor('view')
await page.waitFor('view') lifeCycleNum = await page.callMethod('getLifeCycleNum')
lifeCycleNum = await page.callMethod('getLifeCycleNum') expect(lifeCycleNum).toBe(0)
expect(lifeCycleNum).toBe(-10) })
page = await program.navigateBack() it('onUnload', async () => {
await page.waitFor('view') page = await program.reLaunch(HOME_PATH)
lifeCycleNum = await page.callMethod('getLifeCycleNum') await page.waitFor(700)
expect(lifeCycleNum).toBe(0) lifeCycleNum = await page.callMethod('getLifeCycleNum')
}) expect(lifeCycleNum).toBe(-100)
it('onUnload', async () => { await page.callMethod('setLifeCycleNum', 0)
page = await program.reLaunch(HOME_PATH) })
await page.waitFor(700) it('onBackPress', async () => {
lifeCycleNum = await page.callMethod('getLifeCycleNum') page = await program.navigateTo(PAGE_PATH)
expect(lifeCycleNum).toBe(-100) await page.waitFor(700)
await page.callMethod('setLifeCycleNum', 0) lifeCycleNum = await page.callMethod('getLifeCycleNum')
}) expect(lifeCycleNum).toBe(120)
it('onBackPress', async () => { page = await program.navigateBack()
page = await program.navigateTo(PAGE_PATH) await page.waitFor('view')
await page.waitFor(700) lifeCycleNum = await page.callMethod('getLifeCycleNum')
lifeCycleNum = await page.callMethod('getLifeCycleNum') if (process.env.uniTestPlatformInfo.startsWith('android')) {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(lifeCycleNum).toBe(130)
} else if(process.env.uniTestPlatformInfo.startsWith('web')){
expect(lifeCycleNum).toBe(120)
}
page = await program.navigateBack()
await page.waitFor('view')
lifeCycleNum = await page.callMethod('getLifeCycleNum')
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(lifeCycleNum).toBe(20) expect(lifeCycleNum).toBe(20)
} else if(process.env.uniTestPlatformInfo.startsWith('web')){ } else if (process.env.uniTestPlatformInfo.startsWith('web')) {
expect(lifeCycleNum).toBe(10) expect(lifeCycleNum).toBe(10)
} }
await page.callMethod('setLifeCycleNum', 0) await page.callMethod('setLifeCycleNum', 0)
}) })
}) })
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册