Actualmente estoy interceptando la solicitud de authorization.oauth2 con éxito, pero lo que me gustaría hacer entonces es realizar una solicitud a mi servidor local (una ruta que no existe en la aplicación). Sin embargo, cuando hago esto, aparece un error 404.
¿Hay alguna forma de interceptar una solicitud a una ruta que no existe?
cy.intercept('*authorization.oauth2*', req => { cy.request('POST', '/auth/intercept/handle'); req.reply(''); }); // This route doesn't exist: cy.intercept('POST', '/auth/intercept/handle', req => { // Handle stuff });Esta es la salida de la solicitud:
cy.request() failed on: https://localhost:4200/auth/intercept/handle The response we received from your web server was: > 404: Not Found This was considered a failure because the status code was not 2xx or 3xx. If you do not want status codes to cause failures pass the option: failOnStatusCode: false ----------------------------------------------------------- The request we sent was: Method: POST URL: https://localhost:4200/auth/intercept/handle Headers: { "Connection": "keep-alive", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/8.1.0 Chrome/89.0.4328.0 Electron/12.0.0-beta.14 Safari/537.36", "accept": "/", "accept-encoding": "gzip, deflate", "content-length": 0 } ----------------------------------------------------------- The response we got was: Status: 404 - Not Found Headers: { "x-powered-by": "Express", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "x-content-type-options": "nosniff", "content-type": "text/html; charset=utf-8", "content-length": "161", "date": "Tue, 03 Aug 2021 19:57:39 GMT", "connection": "keep-alive" } Body: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Error</title> </head> <body> <pre>Cannot POST /auth/intercept/handle</pre> </body> </html> Because this error occurred during a after each hook we are skipping the remaining tests in the current suite: Roles Pageen lugar de hacer un cy.intercept para hacer una solicitud de publicación desde el cy intercept, intente usar cy.intercept para responder directamente a su interfaz con los datos que desea incluir. Después de todo, el propósito de cy.intercept es interceptar solicitudes para cambiar datos en la solicitud e inducir comportamientos que queremos probar en nuestra interfaz.
Prueba algo como esto:
const res = { message: true } cy.intercept( { method: 'POST', url: '*authorization.oauth2*' }, res )