|
4 | 4 | * Custom command to get the intercepted API aliases stored in Cypress environment variables. |
5 | 5 | * This command returns the object containing all registered API interception aliases. |
6 | 6 | * |
7 | | - * @returns {Object} An object where keys are the alias names and values are typically the same alias names |
| 7 | + * @returns {Object} An object where keys are in format method-alias(e.g. post-myApiAlias) and values are typically the same alias names |
8 | 8 | * @example |
9 | 9 | * cy.getInterceptedApiAliases().then((aliases) => { |
10 | 10 | * Check if a specific alias exists |
11 | | - * expect(aliases).to.have.property('myApiAlias'); |
| 11 | + * expect(aliases).to.have.property('post-myApiAlias'); |
12 | 12 | * |
13 | 13 | * Get the number of registered aliases |
14 | 14 | * const aliasCount = Object.keys(aliases).length; |
@@ -88,13 +88,14 @@ Cypress.Commands.add( |
88 | 88 |
|
89 | 89 | // Check if this request is already registered |
90 | 90 | cy.getInterceptedApiAliases().then((interceptedAliasesMap) => { |
| 91 | + const aliasObjectKey = `${method.toLowerCase()}-${alias}`; |
91 | 92 | // Check if this request is already registered |
92 | | - const isAlreadyRegistered = !!interceptedAliasesMap[alias]; |
| 93 | + const isAlreadyRegistered = !!interceptedAliasesMap[aliasObjectKey]; |
93 | 94 |
|
94 | 95 | // Register the intercept if not already done |
95 | 96 | if (!isAlreadyRegistered) { |
96 | 97 | cy.intercept(method, urlPattern).as(alias); |
97 | | - cy.setInterceptedApiAlias(alias); |
| 98 | + cy.setInterceptedApiAlias(aliasObjectKey, alias); |
98 | 99 | } |
99 | 100 |
|
100 | 101 | // Execute the function that triggers the API call |
|
0 commit comments