调用的js: wx.showActionSheet({
itemList: that.data.empList,
success: function (res) {
var empListIdS = that.data.empListIdS,
bind_Id = empListIdS[res.tapIndex];
wx.showModal({
content: '您确定要切换工号为' + that.data.empList[res.tapIndex] + '为技师吗?',
success: function (res1) {
console.log(res1)
if (res1.confirm) {
that.setData({
bind_Id: bind_Id
});
that.getEmplInfo();
}
}
});
}
})
}
脚本中的第一个mock:
let setshowModal_list = '';
let showActionSheet_content = '';
await miniProgram.exposeFunction('setshowModal', function (item) {
setshowModal_list = item
})
await miniProgram.exposeFunction('setshowActionSheet', function (item1) {
showActionSheet_content = item1
})
await miniProgram.mockWxMethod('showActionSheet', function (obj) {
setshowActionSheet(obj.itemList)
return { tapIndex: 1 }
})
await miniProgram.mockWxMethod('showModal', function (obj){
setshowModal(obj.content)
return{confirm:true,
cancel:false}
})
await miniProgram.restoreWxMethod('showActionSheet')
await miniProgram.restoreWxMethod('showModal')
await employee_page.waitFor(3000)
脚本中的第二个mock:
let setshowModal_performancesum = '';
let showActionSheet_list_performancesum= '';
await miniProgram.exposeFunction('setshowModal_performancesum', function (content) {
setshowModal_performancesum = content
})
await miniProgram.exposeFunction('setshowActionSheet_per', function (itemList) {
showActionSheet_list_performancesum = itemList
})
await miniProgram.mockWxMethod('showActionSheet', function (obj1) {
console.log('调用showActionSheet组件返回列表',obj1.itemList)
setshowActionSheet_per(obj1.itemList)
return { tapIndex: 1 }
})
await miniProgram.mockWxMethod('showModal', function (obj) {
console.log('调用showModal组件0000000000000000000000000000000')
setshowModal_performancesum(obj.content)
return{confirm:true,
cancel:false}
})
await miniProgram.restoreWxMethod('showActionSheet')
await miniProgram.restoreWxMethod('showModal')
第二个mock方法内的log信息均未打印,showActionSheet_list_performancesum值正常打印,setshowModal_performancesum的值为'小程序接口出错,
错误代码500';第一次mock正常执行
自己的问题