File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change 1212 * @param {string } options.method - HTTP method (default: 'POST')
1313 * @param {string|RegExp } options.urlPattern - URL pattern to intercept
1414 * @param {Function } options.triggerFn - Function that triggers the API call
15+ * @param {Function } [options.onApiResponse] - Optional callback function that receives the interception object after the API call completes.
16+ * Use this to perform assertions on the response, extract data, or perform additional actions based on the API result.
17+ * Default is a no-op function. e.g. { onApiResponse: (interception) => { expect(interception.response.statusCode).to.equal(200); } }
1518 */
1619Cypress . Commands . add (
1720 'interceptApi' ,
18- ( { alias, method = 'POST' , urlPattern, triggerFn } ) => {
21+ ( {
22+ alias,
23+ method = 'POST' ,
24+ urlPattern,
25+ triggerFn,
26+ onApiResponse = ( ) => {
27+ /* default implementation */
28+ } ,
29+ } ) => {
1930 /* ===== TODO: Remove this block once interceptApi command becomes stable ===== */
2031 const envVars = Cypress . env ( ) ;
2132 cy . log ( 'Cypress Environment Variables:' ) ;
@@ -39,6 +50,8 @@ Cypress.Commands.add(
3950 triggerFn ( ) ;
4051
4152 // Wait for the intercepted request to complete
42- cy . wait ( `@${ alias } ` ) ;
53+ cy . wait ( `@${ alias } ` ) . then ( ( interception ) => {
54+ onApiResponse ( interception ) ;
55+ } ) ;
4356 }
4457) ;
You can’t perform that action at this time.
0 commit comments