Skip to content

Commit 31772fd

Browse files
feat(cypress-commands): add clearUi5Input to cypress commands (#4980)
1 parent 680c33b commit 31772fd

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/cypress-commands/src/commands.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ declare global {
99
* @example cy.get('[ui5-input]').typeIntoUi5Input('Hello World');
1010
*/
1111
typeIntoUi5Input(text: string, options?: Partial<TypeOptions>): Chainable<Element>;
12+
/**
13+
* Clears a value from ui5-webcomponent that offers a typeable input field.
14+
*
15+
* @example cy.get('[ui5-input]').clearUi5Input();
16+
*/
17+
clearUi5Input(options?: Partial<ClearOptions>): Chainable<Element>;
1218
/**
1319
* Types a value with a delay into an ui5-webcomponent that offers a typeable input field.
1420
*
@@ -69,6 +75,12 @@ Cypress.Commands.add('typeIntoUi5Input', { prevSubject: 'element' }, (subject, t
6975
.type(text, { force: true, ...options });
7076
});
7177

78+
Cypress.Commands.add('clearUi5Input', { prevSubject: 'element' }, (subject, text, options = {}) => {
79+
cy.wrap(subject)
80+
.findShadowInput()
81+
.clear({ force: true, ...options });
82+
});
83+
7284
Cypress.Commands.add(
7385
'typeIntoUi5InputWithDelay',
7486
{ prevSubject: 'element' },

packages/cypress-commands/test/UI5WebComponentsChild.cy.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ describe('UI5 Web Components - Child Commands', () => {
6767
cy.findByTestId('input').should('have.attr', 'value', 'Hello World!');
6868
});
6969

70+
it('clearUi5Input', () => {
71+
cy.mount(<Input data-testId={'input'} value="Hello World" />);
72+
cy.findByTestId('input').clearUi5Input();
73+
cy.findByTestId('input').should('have.attr', 'value', '');
74+
});
75+
7076
it('typeIntoUi5TextArea', () => {
7177
cy.mount(<TextArea data-testId="textArea" />);
7278

0 commit comments

Comments
 (0)