Search code examples
file-uploadcypress

Cypress: Upload file exent execution


I have such an input file tag:

                      <input type="file" 
                         #fileInput formControlName="browseDocument"
                         id="uploadFile"
                         (change)="uploadFileEvt($event)"
                         name="uploadFile"
                         accept=".pdf,.xml"
                  />

I want to test the upload file, but I need that uploadFileEvt function will be executed.

How could I cause it to happen in the test?

Thanks!


Solution

  • I think you just need to use .trigger('change') after the .attachFile() or .selectFile(),

    cy.get('input[type=file]')
      .selectFile({...})
      .trigger('change')