我正在自动化我的REST API。我有一个 POST 请求,例如:
POST /upload
文件(应用程序/x-compressed-tar)类型和
"Content-Type": "multipart/form-data"
.
cypressTestFile.ts
cy.fixture(filePath, 'binary').then((binary) => {
const blob = Cypress.Blob.binaryStringToBlob(binary);
const formData = new FormData();
formData.set('file', blob, filePath); <-- formData is empty {}
cy.request({
method: 'POST',
url: `/upload`,
form: true,
headers: {
"Content-Type": "multipart/form-data"
},
body: {
file: blob,
type: "application/x-compressed-tar"
}
}).as('response').then(res => {
expect(res.status).to.equal(201);
});
})
这没有按预期工作。
任何帮助表示赞赏!
谢谢