开发工具版本:stable 1.03.2006090
系统版本:windows10
示例里的log输出是 'test',但我实际运行得到的输出是 'ok',这是为什么?
完整代码如下
```javascript
const automator = require('miniprogram-automator')
describe('api', () => {
let miniProgram
beforeAll(async () => {
miniProgram = await automator.launch({
projectPath: 'E:\\******\\******'
})
}, 30000)
afterAll(async () => {
await miniProgram.disconnect()
})
it('request', async () => {
const mockData = [
{
rule: 'testRequest',
result: {
data: 'test',
cookies: [],
header: {},
statusCode: 200,
},
},
]
await miniProgram.mockWxMethod(
'request',
function (obj, data) {
for (let i = 0, len = data.length; i < len; i++) {
const item = data[i]
const rule = new RegExp(item.rule)
if (rule.test(obj.url)) {
return item.result
}
// 没命中规则的真实访问后台
return new Promise(resolve => {
obj.success = res => resolve(res)
obj.fail = res => resolve(res)
this.origin(obj)
})
}
},
mockData,
)
const result = await miniProgram.callWxMethod('request', {
url: 'https://14592619.qcloud.la/testRequest',
})
console.log(result.data) // -> 这里期望输出是'test',但实际输出是'ok'
await miniProgram.restoreWxMethod('request')
}, 30000)
})
```