【发布时间】:2021-10-22 15:56:31
【问题描述】:
我正在使用 NodeJs 构建一个应用程序,其中将上传多个文件。以下是我的测试用例,我收到此错误Argument of type 'string[]' is not assignable to parameter of type 'MultipartValueSingle'.
这是测试用例
it('Create feed (POST)', () => {
const video = path.resolve(__dirname, `../test-files/movie_video.mp4`);
const image = path.resolve(__dirname, `../test-files/thumbnail.jpg`);
const pdfDoc = path.resolve(__dirname, `../test-files/pdf_doc.pdf`);
const multipleFiles : string[] = [video, image, pdfDoc]
return request(app.getHttpServer())
.post('/feed')
.set('content-type', 'application/octet-stream')
.set('Authorization', 'Bearer ' + accessToken)
.field('text', 'Aenean imperdiet. Nam ipsum risus,. Curabitur suscipit suscipit tellus.')
.field('payment_amount', 0)
.attach('postDocs', multipleFiles)
.expect(function (res) {
if (!('message' in res.body) || !('payload' in res.body)) {
throw new Error('Response should contain message and payload.');
} else if (res.body.message !== StatusMessages.Default) {
throw new Error('User not logged in');
}
if (!('user' in res.body.payload)) {
throw new Error('Payload should contain user.');
}
adminAccessToken = res.body.payload.access_token;
});
});
【问题讨论】:
-
文档说:
To send a file use .attach(name, [file], [options]). You can attach multiple files by calling .attach multiple times.
标签: javascript node.js jestjs ts-jest