Skip to content

Instantly share code, notes, and snippets.

@rowellx68
Created February 11, 2025 17:45
Show Gist options
  • Save rowellx68/c94d305e5f4d32ae0a8eb80d597c23a0 to your computer and use it in GitHub Desktop.
Save rowellx68/c94d305e5f4d32ae0a8eb80d597c23a0 to your computer and use it in GitHub Desktop.
Selecting option from Mantine Select
/* eslint-disable @typescript-eslint/no-namespace */
/// <reference types="cypress" />
declare global {
namespace Cypress {
interface Chainable {
selectMantine(
optionText: string,
options?: Partial<
Cypress.Loggable &
Cypress.Timeoutable &
Cypress.Withinable &
Cypress.Shadow
>
): Chainable<JQuery<HTMLElement>>;
}
}
}
Cypress.Commands.add('selectMantine', { prevSubject: true }, (subject, optionText, options) => {
cy.wrap(subject).get('input.mantine-Select-input').click();
cy.wrap(subject).get('label.mantine-Select-label').then((label) => {
cy.get(`[aria-labelledby="${label.attr('id')}"].mantine-Select-options .mantine-Select-option`, options)
.contains(optionText).click();
});
return cy.wrap(subject).get('input.mantine-Select-input');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment