Estoy usando el fixture de ciprés y la intercept para cargar un archivo y también validar si el punto final de carga (publicación) fue exitoso. aquí está el código:
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); }); }); }); });No estoy exactamente seguro de a qué se refiere el error, pero supongo que podría ser un problema asíncrono.
gracias por su ayuda
El .wait() debe estar encadenado a un cy cuando pasa un 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); }); Cuando pasa un agrumento de tiempo (es decir, 500 ) .wait() se puede encadenar a un cy o cualquier otro comando.
cy.get('.selector') .wait(1000) cy.wait(500)