Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
TypeScript/Cypress command which accept only defined value of parameter

I wrote cypress command with parameter and I would like to change it that function accept only certain values, e.g. I would like that columnValue can be only 'xxx' or 'yyy' or 'zzz'. How can I do it?

Cypress.Commands.add('addColumnAsDimension', (columnName: string) => {
  chartMenu.addColumnButton.click();
  chartMenu.columnNameButton(columnName).click();
  chartMenu.addAsDimensionButton.click();
});

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use a union type for that:

type Column = 'xxx' | 'yyy' | 'zzz'

Cypress.Commands.add('addColumnAsDimension', (columnName: Column) => {
  chartMenu.addColumnButton.click();
  chartMenu.columnNameButton(columnName).click();
  chartMenu.addAsDimensionButton.click();
});

Also, if you want the complier to check your custom Cypress method invocation, you have to add a type definition for the method as well:

declare namespace Cypress {
  interface Chainable<Subject> {
       addColumnAsDimension(columnName: Column): void
    }
}

Now the compiler checks your arguments: enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!