mardi 24 octobre 2017

How to test sending multiple images in one field using chai-http/mocha

It's my first time using a testing framework and I'm trying to figure out how I would send multiple images in a chai request. When trying to put the images inside an array in .attach I get the error that Arrays are not supported.

I've looked around and cannot seem to find an answer on how to attach multiple images in one field?

My test code is shown below;

it('Should show error if user tries to upload more than one image', (done) => {
            chai.request(server)
                .post('/api/uploadImages')
                .set('Authorization', token)
                .attach("image", [readFileSync(testImages + 'test1.jpg'), readFileSync(testImages + 'test2.jpg')], ["test1.jpg", "test2.jpeg"])
                .end((err, res) => {
                    should.exist(err);
                    res.redirects.length.should.eql(0);
                    res.status.should.eql(401);
                    res.type.should.eql('application/json');
                    res.body.message.should.eql("You can only upload one image.");
                    done();
                })
        })

Any help/advice is much appreciated!

Aucun commentaire:

Enregistrer un commentaire