Skip to content

Commit 43b9b50

Browse files
Add expect_inline_field_errors command
1 parent a65f96f commit 43b9b50

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cypress/support/assertions/expect_alerts.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,19 @@ Cypress.Commands.add(
150150
.click();
151151
}
152152
);
153+
154+
/**
155+
* Custom Cypress command to validate inline field error messages.
156+
* @param {Object} options - Options for the command.
157+
* @param {string} options.containsText - Text that the error message should contain. This parameter is required.
158+
* @returns {Cypress.Chainable} - The error message element if found, or an assertion failure.
159+
* @example
160+
* cy.expect_inline_field_errors({ containsText: 'blank' });
161+
* cy.expect_inline_field_errors({ containsText: 'taken' });
162+
*/
163+
Cypress.Commands.add('expect_inline_field_errors', ({ containsText }) => {
164+
if (!containsText) {
165+
cy.logAndThrowError('containsText is required');
166+
}
167+
return cy.contains('#name-error-msg', containsText);
168+
});

0 commit comments

Comments
 (0)