I just started to learn do test with supertest and mocha. I've read the api document of supertest and it said that supertest support all lower-level API provided by superagent. SuperAgent said we can send a formData object by:
request.post('/user')
.send(new FormData(document.getElementById('myForm')))
.then(callback)
But when I try to send a formData object with supertest like this:
server
.post('/goal_model/images/' + userId + '/' + tmid)
.set('Authorization',`Bearer ${token}`)
.send(formData)
.expect("Content-type",/json/)
.expect(201)
.end(function(err,res){
should(res.status).equal(201);
console.log(res.message);
done();
});
Where the formData is like:
let file;
let formData = new FormData();
let fn = "../../../Downloads/Images/5k.jpg";
formData.append("image", file);
Then when I try to send this object it just said:
TypeError: "string" must be a string, Buffer, or ArrayBuffer
Does it possible to send a formData object in this way? What did I do wrong or how to do that? If not, why? I've searched many relative questions but none can solve my problem. I'm really in struglling now.