Skip to content

Commit 3d0e61c

Browse files
Included API method names in keys of interceptedAliases env variable
1 parent e8d8dec commit 3d0e61c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

cypress/support/commands/api_commands.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* Custom command to get the intercepted API aliases stored in Cypress environment variables.
55
* This command returns the object containing all registered API interception aliases.
66
*
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
88
* @example
99
* cy.getInterceptedApiAliases().then((aliases) => {
1010
* Check if a specific alias exists
11-
* expect(aliases).to.have.property('myApiAlias');
11+
* expect(aliases).to.have.property('post-myApiAlias');
1212
*
1313
* Get the number of registered aliases
1414
* const aliasCount = Object.keys(aliases).length;
@@ -88,13 +88,14 @@ Cypress.Commands.add(
8888

8989
// Check if this request is already registered
9090
cy.getInterceptedApiAliases().then((interceptedAliasesMap) => {
91+
const aliasObjectKey = `${method.toLowerCase()}-${alias}`;
9192
// Check if this request is already registered
92-
const isAlreadyRegistered = !!interceptedAliasesMap[alias];
93+
const isAlreadyRegistered = !!interceptedAliasesMap[aliasObjectKey];
9394

9495
// Register the intercept if not already done
9596
if (!isAlreadyRegistered) {
9697
cy.intercept(method, urlPattern).as(alias);
97-
cy.setInterceptedApiAlias(alias);
98+
cy.setInterceptedApiAlias(aliasObjectKey, alias);
9899
}
99100

100101
// Execute the function that triggers the API call

0 commit comments

Comments
 (0)