abramenal / cypress-file-upload

File upload testing made easy
https://npm.im/cypress-file-upload
MIT License
498 stars 90 forks source link

[Bug] Getting malformed JSON file payload #378

Open aakashkalra47 opened 1 year ago

aakashkalra47 commented 1 year ago

Current behavior:

When I upload a JSON file. The file payload I get is malformed. It should be formatted JSON file and not double stringified JSON string.

File content

{"key1":"value1","key2":"value2","key3":"value3","key4":"value4"}

After uploading the file using attachFile I am getting file payload as -

Output

{
  "key1": "value1",
  "key2": "value2",
  "key3": "value3",
  "key4": "value4"
}

Desired behavior:

The data should not get updated and I should get file payload as JSON string or I should be able to pass the fileContent by parsing the JSON object using JSON.stringfy(fileData) as we are doing earlier (before https://github.com/abramenal/cypress-file-upload/issues/175).

I should get payload data as {"key1":"value1","key2":"value2","key3":"value3","key4":"value4"}

Steps to reproduce: (app code and test code)

  1. Try to attach a JSON file to a Dropzone component which reads the file:
    cy.get(<selector>).attachFile(
          <JSON fixture file>,
          { subjectType: 'drag-n-drop' }
    )

    or I also tried to read the file using

    
    cy.fixture(jsonFileName).then(content => {
         return cy.get(<selector>).attachFile(
        { fileContent, fileName: jsonFileName, mimeType: 'application/json', encoding},
        { subjectType: 'drag-n-drop' }
      )
    })


### Versions
Cypress@^7.7.0,
Cypress-file-upload@^5.0.8
Chrome: 108