https://cypress.io logo
Mixing Async and Sync code
# i-need-help
k
Greetings Everyone, Implemented a Step definition (Cucumber) in cypress and I wanted to ensure the below code is not affected by https://docs.cypress.io/guides/core-concepts/introduction-to-cypress#Mixing-Async-and-Sync-code. The dataTestId variable is initialised before executing any cy commands. Can I seek advise in rewriting this code to avoid flake? `When( /the user clicks maximise button of (lyactuals|proposed|slotting) table/, (dataTestIdInd: string) => { let dataTestId: string; /* Indicator to choose the Deals table according to the validation*/ switch (true) { case dataTestIdInd?.includes('lyactuals'): dataTestId = 'LastYearActualsTable'; break; case dataTestIdInd?.includes('proposed'): dataTestId = 'ReadonlyProposedTable'; break; case dataTestIdInd?.includes('slotting'): dataTestId = 'SlottingBoardTable'; } cy.findByTestId(dataTestId) .find('section > div') .then(($div) => { if ($div.length > 1) { return; } cy.wrap($div).find(
[type="button"]
).click(); }); }`