Reusing Object Literals Created by Destructuring
I am trying to reuse object literals for both asynchronous calls. At the end, my waiter should check the success of the deleteBucket call. The problem is I can't seem to do it, or it says I have dup variables:
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
})
Someone told me that I could put () around the second, but this bombing gave me an error 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
})
This works, but I need to change the names of the allowed objects, which I don't want to do:
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
})
UPDATE:
someone suggested that I need half the colon after the const line. It doesn't matter, I still get the same error when I run it:
source to share
You don't need to change names. There is probably something wrong somewhere in your program
let {x,y,z} = {x: 1, y: 2, z: 3};
console.log(x,y,z);
// 1 2 3
({x,y,z} = {x: 10, y: 20, z: 30});
console.log(x,y,z);
// 10 20 30
Oh, I see you are missing the semicolon!
which explains that "TypeError: is (0 , _context4.t0)
not a function" you saw - there is not much you can do here; I know semicolons suck, but you'll have to use them in this particular scenario.
// missing semicolon after this line!
let { failure, success, payload } = await deployApi.createBucket(options); // add semicolon here!
// without the semicolon, it tries to call the above line as a function
({ failure, success, payload} = await deployApi.deleteBucket(options.branch))
"It does not matter"
Yes it is; try the same piece of code I had above, but without semicolons - you will recognize a familiarTypeError
let {x,y,z} = {x: 1, y: 2, z: 3}
console.log(x,y,z)
// 1 2 3
({x,y,z} = {x: 10, y: 20, z: 30})
// Uncaught TypeError: console.log(...) is not a function
console.log(x,y,z)
source to share