lundi 3 février 2020

Unable to test file uploads on cypress using - cypress-file-upload error

I am attempting to test file upload with Cypress using cypress-file-upload error. The error is: [cypress-file-upload error]: One or more field is invalid within given file(s). Please look into docs to find supported "fileOrArray" values

I use antd for my file upload and my upload component looks like this:

<Upload
  beforeUpload={this.beforeUpload}
  listType="picture-card"
  fileList={fileMain}
  onChange={this.handleMainPicChange}
  onRemove={this.removeMainFile}
  onPreview={this.handleMainPreview}
  id="mainImage"
  name="mainImage"
  data-testid="main-image"
>
  {fileMain && fileMain.length >= 1 ? null : uploadButton}
</Upload>

My test looks like this:

import "cypress-file-upload";

describe("products catalog", () => {
  it("uploads picture", () => {
    const mainImage = "download.jpg";
    cy.fixture(mainImage).then(fileContent => {
      cy.get(".ant-upload-select-picture-card")
        .first()
        .within(() => {
          cy.get("input", { force: true }).upload(
            { force: true },
            {
              fileContent,
              fileName: mainImage,
              mimeType: "image/jpeg"
            },
            { subjectType: "input" }
          );
        });
    });
  });
})

Aucun commentaire:

Enregistrer un commentaire