I'm using mocha as a test framework, and chakram for API calls.
I have an array of objects, I want to loop over them and POST each one to an API, how can I do this? What I've tried so far doesn't give any output from the each iteration.
This is what I've come up with so far, using it-each to loop over an array, then chakram to post each one. I'm not quite sure how to tie in the chakram promise chain with the it-each
const itEach = require('it-each')({ testPerIteration: true });
const url = ""
things = [{"title":"A"},{"title":"B"}]
it.each(things, "calling API", ['element'], (element, next) =>{
console.log("about to post a thing " + JSON.stringify(element))
chakram
.post(url, element)
.then(uploadResponse => {
expect(uploadResponse).to.have.status(200)
console.log("finished upload for element " + element)
next()
})
})
What have I got wrong? JS isn't my language, I'm not very good with promise chains.