【发布时间】:2017-11-12 03:42:54
【问题描述】:
我正在尝试为两个异步调用重用对象字面量。最后,我的期望应该检查 deleteBucket 调用是否成功。问题是我不能这样做,或者它说我已经定义了 dup 变量:
it('can delete a bucket', async () => {
const options = { branch: '11' }
let { failure, success, payload } = await deployApi.createBucket(options)
let { failure, success, payload} = await deployApi.deleteBucket(options.branch)
expect(success).to.be.true
})
有人告诉我,我可以在第二个周围加上 (),但这给了我一个 TypeError: (0 , _context4.t0) is not a function 错误:
it('can delete a bucket', async () => {
const options = { branch: '11' }
let { failure, success, payload } = await deployApi.createBucket(options)
({ failure, success, payload} = await deployApi.deleteBucket(options.branch))
expect(success).to.be.true
})
这确实有效,但需要我更改我不想做的已解析对象的名称:
it('can delete a bucket', async () => {
const options = { branch: '11' }
let { failure, success, payload } = await deployApi.createBucket(options)
let { failure1, success1, payload1} = await deployApi.deleteBucket(options.branch)
expect(success1).to.be.true
})
更新:
有人建议我在 const 行之后需要一个分号。没有任何区别,我运行时仍然遇到同样的错误:
【问题讨论】:
-
我看到你的更新,包括截图。你能更仔细地阅读我的答案吗?它准确地显示了您需要放置分号的位置。您的屏幕截图在错误(不必要的)位置显示了一个分号
-
仅供参考,
async/await不是 ES6 (ES2015) 的一部分。它是今年发布的 ES2017 的一部分。
标签: javascript asynchronous async-await ecmascript-2017