提交 3c30f03d 编写于 作者: 雪洛's avatar 雪洛

feat: 移除uniCloud相关测试例的page.waitFor(3000)

上级 47cb066c
......@@ -12,7 +12,6 @@ describe('unicloud-call-function', () => {
it('callFunction', async () => {
await page.callMethod('callFunction')
await page.waitFor(3000)
const {
callFunctionResult,
callFunctionError
......
......@@ -46,11 +46,11 @@
console.log(title, content)
}
},
callFunction: function () {
async callFunction () : Promise<void> {
uni.showLoading({
title: '加载中...'
})
uniCloud.callFunction({
await uniCloud.callFunction({
name: 'echo-cf',
data: {
num: 1,
......
......@@ -11,20 +11,13 @@ describe('unicloud-database', () => {
})
it('databaseBasic', async () => {
await page.callMethod('dbRemove')
await page.waitFor(3000)
await page.callMethod('dbAdd')
await page.waitFor(1500)
await page.callMethod('dbBatchAdd')
await page.waitFor(1500)
await page.callMethod('dbGet')
await page.waitFor(1500)
await page.callMethod('dbGetWithCommand')
await page.waitFor(1500)
await page.callMethod('dbUpdate')
await page.waitFor(1500)
await page.callMethod('dbRemove')
await page.waitFor(1500)
const {
addId,
batchAddIds,
......@@ -34,7 +27,7 @@ describe('unicloud-database', () => {
getWithCommandData,
removeDeleted,
} = await page.data()
expect(addId !== '').toBe(true)
expect(batchAddIds.length).toBe(2)
expect(batchAddinserted).toBe(2)
......@@ -42,15 +35,13 @@ describe('unicloud-database', () => {
expect(getWithCommandData.length).toBe(1)
expect(updateUpdated).toBe(3)
expect(removeDeleted).toBe(3)
})
it('databaseLookup', async () => {
await page.callMethod('dbLookupInit')
await page.waitFor(3000)
await page.callMethod('dbLookup')
await page.waitFor(1500)
const {
lookupData
} = await page.data()
......@@ -58,4 +49,4 @@ describe('unicloud-database', () => {
expect(lookupData[0]['foreign_id'].length).toBe(1)
expect(lookupData[1]['foreign_id'].length).toBe(1)
})
});
\ No newline at end of file
});
......@@ -40,10 +40,15 @@
onLoad() {
},
onUnload() {
if(this.isUniTest){
if (this.isUniTest) {
uni.hideToast()
}
},
computed: {
dataTag() : string {
return this.isUniTest ? 'default-tag' + Date.now() : 'default-tag'
}
},
methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
......@@ -56,18 +61,18 @@
uni.showToast({
title: content
})
console.log(title, content)
console.error(title, content)
}
},
dbAdd: function () {
async dbAdd() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
await db.collection('type')
.add({
num: 1,
tag: 'default-tag',
tag: this.dataTag,
date: new Date()
})
.then(res => {
......@@ -82,18 +87,18 @@
this.notify(error.errMsg, '错误')
})
},
dbBatchAdd() {
async dbBatchAdd() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
await db.collection('type')
.add([{
num: 2,
tag: 'default-tag',
tag: this.dataTag,
}, {
num: 3,
tag: 'default-tag',
tag: this.dataTag,
}])
.then((res) => {
uni.hideLoading()
......@@ -109,14 +114,14 @@
this.notify(error.errMsg, '错误')
})
},
dbGet() {
async dbGet() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
await db.collection('type')
.where(
'tag == "default-tag"'
`tag == "${this.dataTag}"`
)
.field('num, tag')
.orderBy('num desc')
......@@ -135,14 +140,15 @@
this.notify(error.errMsg, '错误')
})
},
dbGetWithCommand() {
async dbGetWithCommand() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
await db.collection('type')
.where({
num: db.command.gt(1)
num: db.command.gt(1),
tag: this.dataTag
})
.field('num, tag')
.orderBy('num desc')
......@@ -161,14 +167,14 @@
this.notify(error.errMsg, '错误')
})
},
dbUpdate() {
async dbUpdate() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
await db.collection('type')
.where(
'tag == "default-tag"'
`tag == "${this.dataTag}"`
)
.update({
num: 4
......@@ -185,14 +191,14 @@
this.notify(error.errMsg, '错误')
})
},
dbRemove() {
async dbRemove() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
await db.collection('type')
.where(
'tag == "default-tag"'
`tag == "${this.dataTag}"`
)
.remove()
.then(res => {
......@@ -207,17 +213,17 @@
this.notify(error.errMsg, '错误')
})
},
dbLookupInit() {
async dbLookupInit() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('local')
.where('tag == "default-tag"')
await db.collection('local')
.where(`tag == "${this.dataTag}"`)
.remove()
.then(() : Promise<UniCloudDBRemoveResult> => {
return db.collection('foreign')
.where('tag == "default-tag"')
.where(`tag == "${this.dataTag}"`)
.remove()
})
.then(() : Promise<UniCloudDBBatchAddResult> => {
......@@ -225,12 +231,12 @@
.add([{
id: "local_1",
name: "local_1_name",
tag: "default-tag",
tag: this.dataTag,
foreign_id: "foreign_1"
}, {
id: "local_2",
name: "local_2_name",
tag: "default-tag",
tag: this.dataTag,
foreign_id: "foreign_2"
}])
})
......@@ -239,11 +245,11 @@
.add([{
id: "foreign_1",
name: "foreign_1_name",
tag: "default-tag"
tag: this.dataTag
}, {
id: "foreign_2",
name: "foreign_2_name",
tag: "default-tag"
tag: this.dataTag
}])
})
.then((_) : void => {
......@@ -257,18 +263,18 @@
this.notify(error.errMsg, '错误')
})
},
dbLookup() {
async dbLookup() : Promise<void> {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
const local = db.collection('local')
.where('tag == "default-tag"')
.where(`tag == "${this.dataTag}"`)
.getTemp()
const foreign = db.collection('foreign')
.where('tag == "default-tag"')
.where(`tag == "${this.dataTag}"`)
.getTemp()
db.collection(local, foreign)
await db.collection(local, foreign)
.get()
.then(res => {
uni.hideLoading()
......
......@@ -13,8 +13,7 @@ describe('unicloud-import-object', () => {
await page.callMethod('addTodo')
await page.callMethod('fail')
await page.callMethod('success')
await page.waitFor(3000)
const {
todoTitle,
todoContent,
......@@ -23,11 +22,11 @@ describe('unicloud-import-object', () => {
failErrCode,
successErrCode,
} = await page.data()
expect(returnTodoTitle).toBe(todoTitle)
expect(returnTodoContent).toBe(todoContent)
expect(failErrCode).toBe('TEST_ERROR_CODE')
expect(successErrCode).toBe(0)
})
});
\ No newline at end of file
});
......@@ -39,7 +39,7 @@
}
},
onUnload() {
if(this.isUniTest){
if (this.isUniTest) {
uni.hideToast()
}
},
......@@ -58,42 +58,42 @@
console.log(title, content)
}
},
addTodo() {
async addTodo() : Promise<void> {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
const title = this.todoTitle
const content = this.todoContent
todo.add(title, content).then((res : UTSJSONObject) : void => {
await todo.add(title, content).then((res : UTSJSONObject) => {
this.returnTodoTitle = res['title'] as string
this.returnTodoContent = res['content'] as string
this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) : void => {
}).catch((err : any | null) => {
const error = err as UniCloudError
console.error(error)
})
},
randomFail() {
async randomFail() : Promise<void> {
const todoObj = uniCloud.importObject('todo', {
errorOptions: {
retry: true
}
})
todoObj.randomFail().then((res : UTSJSONObject) : void => {
await todoObj.randomFail().then((res : UTSJSONObject) => {
this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) : void => {
}).catch((err : any | null) => {
const error = err as UniCloudError
console.error(error)
})
},
fail() {
async fail() {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
todo.fail().then((res : UTSJSONObject) : void => {
await todo.fail().then((res : UTSJSONObject) => {
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
console.log('todo.fail: ', res);
}).catch((err : any | null) : void => {
}).catch((err : any | null) => {
const error = err as UniCloudError
this.failErrCode = error.errCode as string
console.error(error)
......@@ -108,10 +108,10 @@
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
todo.success().then((res : UTSJSONObject) : void => {
todo.success().then((res : UTSJSONObject) => {
this.successErrCode = res['errCode'] as number
this.notify(res['showMessage'] as string, '提示')
}).catch((err : any | null) : void => {
}).catch((err : any | null) => {
const error = err as UniCloudError
console.error(error)
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册