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

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

我正在使用 cypress fixtureintercept 上传文件并验证上传端点 (post) 是否成功。这是代码:

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);
        });
    });
  });
});

我不太确定错误指的是什么,但我猜它可能是异步问题。

感谢您的帮助

传递别名时的 .wait() must be chained off a cy

// 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);
    });

当传递一个时间参数(即 500)时,.wait() 可以链接到 cy 或任何其他命令。

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

cy.wait(500)