I am testing the addition of products, I want to add 10 products, for this I use the https://www.npmjs.com/package/multer library.
My test:
describe('Test products', () => {
describe('POST /api/products/add', () => {
it(`Should create ${addProductCount} products with 0...1000 price`, (done) => {
let operationCount = addProductCount;
for (let i = 0; i < addProductCount; i++) {
let product = utils.getFakeProduct(2, 1000);
chai
.request(server)
.post('api/products/add')
.set('token', constants.merchantToken)
.field(product)
.attach('product_photos', './test/path/products/test1.jpeg', 'test1.jpeg')
.attach('product_photos', './test/path/products/test2.jpg', 'test2.jpg')
.attach('product_photos', './test/path/products/test3.png', 'test3.png')
.end((err, res) => {
operationCount--;
expect(res).have.status(200);
expect(res.body).have.property('message');
expect(res.body.message).to.be.equal('Product added');
if (operationCount == 0) {
done();
}
});
}
});
});
});
When performing tests, I get an error:
TypeError: source.on is not a function
at Function.DelayedStream.create (node_modules\delayed-stream\lib\delayed_stream.js:33:10)
at FormData.CombinedStream.append (node_modules\combined-stream\lib\combined_stream.js:44:37)
at FormData.append (node_modules\form-data\lib\form_data.js:74:3)
at Test.RequestBase.field (node_modules\superagent\lib\request-base.js:406:23)
at Test.RequestBase.field (node_modules\superagent\lib\request-base.js:387:12)
at Context.field (test/productsTest.js:53:22)
at process.topLevelDomainCallback (domain.js:120:23)
What is my problem? I do not use this function.
Aucun commentaire:
Enregistrer un commentaire