Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
CypressError: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise

I am using cypress fixture and intercept to upload a file and also validate if the upload endpoint (post) was successful. here is the code:

describe('something', () => {
 
  let projectID;

  before(() => {
    projectID = localStorage.getItem('projectID');
   
    cy.intercept('POST', '/graphql', (req) => {
      cy.log(req.body);
      if (req.body.operationName === 'postRequest') {
        req.alias = 'postRequest';
      }
    });
  });

  it('should validate file upload', () => {
    const fileName = 'test_file_upload.xlsx';
    cy.get('.file-uploader').should('exist');
    cy.get('.upload-file-label').first().click({ force: true });
    cy.fixture(fileName, 'binary').then((fileContent) => {
      cy.get('input[type=file]')
        .upload(
          {
            fileContent,
            fileName,
            mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
            encoding: 'utf-8',
          },
          { subjectType: 'input' }
        )
        .wait('@postRequest')
        .then((interception) => {
          cy.log(interception.response.body);
        });
    });
  });
});

I am not exactly sure what is error refer to, but I am guessing it might be async issue.

thank you for your help

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The .wait() must be chained off a cy when you pass an alias.

// code looks good until here
cy.get('input[type=file]')
  .upload(
    {
      fileContent,
      fileName,
      mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
      encoding: 'utf-8',
    },
    { subjectType: 'input' }
  )
  cy.wait('@postRequest')
    .then((interception) => {
      cy.log(interception.response.body);
    });

When passed a time agrument (ie. 500) .wait() can be chained off a cy or any other command.

cy.get('.selector')
  .wait(1000)

cy.wait(500)
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!