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 12
12
* @param {string } options.method - HTTP method (default: 'POST')
13
13
* @param {string|RegExp } options.urlPattern - URL pattern to intercept
14
14
* @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); } }
15
18
*/
16
19
Cypress . Commands . add (
17
20
'interceptApi' ,
18
- ( { alias, method = 'POST' , urlPattern, triggerFn } ) => {
21
+ ( {
22
+ alias,
23
+ method = 'POST' ,
24
+ urlPattern,
25
+ triggerFn,
26
+ onApiResponse = ( ) => {
27
+ /* default implementation */
28
+ } ,
29
+ } ) => {
19
30
/* ===== TODO: Remove this block once interceptApi command becomes stable ===== */
20
31
const envVars = Cypress . env ( ) ;
21
32
cy . log ( 'Cypress Environment Variables:' ) ;
@@ -39,6 +50,8 @@ Cypress.Commands.add(
39
50
triggerFn ( ) ;
40
51
41
52
// Wait for the intercepted request to complete
42
- cy . wait ( `@${ alias } ` ) ;
53
+ cy . wait ( `@${ alias } ` ) . then ( ( interception ) => {
54
+ onApiResponse ( interception ) ;
55
+ } ) ;
43
56
}
44
57
) ;
You can’t perform that action at this time.
0 commit comments