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

152
Views
Unable to share aliases across steps in cypress

I am having an issue trying to share an alias between two steps in cypress. Basically what I am trying to do is in the first then step, I get the value and pass it in as a variable storedOddsValue. In the second then step, when I try to get that alias value and complete the step, it fails because I beleive it's coming back with undefined.

I know this because instead of using:

let storedOddsValue = oddslib.from("fractional", cy.get("@storedOddsValue"));

If I replace the alias with the hardcoded value like so:

let storedOddsValue = oddslib.from("fractional", "13/5");

The whole code below executes fine and the assertion passes. So my question is what am I doing wrong, why is it not getting the alias?

Then ("The prices are formatted in fractions by default", () => {
    priceFormatElements.priceFormatDropdown().should('have.value', 'Fraction');
    const oddsValue = oddsSelectionElements.oddsButton().first().invoke("text");

    oddsValue.then((oddsValue) => {
        expect(oddsValue.trim()).contains("/");
        oddsValue.trim();
    }).as("storedOddsValue")
})

Then ("The prices are formatted in {string}", (priceFormat) => {
    let expectedOddsValue;
    let currentOddsValue = oddsSelectionElements.oddsButton().first().invoke("text");
    //let storedOddsValue = oddslib.from("fractional", "13/5");
    let storedOddsValue = oddslib.from("fractional", cy.get("@storedOddsValue"));
    
    switch (priceFormat) {
        case "Fractional":
          expectedOddsValue = storedOddsValue.to("fractional");
          break;
        case "Decimal":
          expectedOddsValue = storedOddsValue.to("decimal", {precision: 2});
          break;
        case "American":
          expectedOddsValue = "+" + storedOddsValue.to("moneyline");  
          break;
        default:
          throw new Error('unknown price format: ' + priceFormat);
    }
    
    currentOddsValue.then((oddsValue) => {
        expect(oddsValue.trim()).equals(expectedOddsValue);
    });
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Not sure what oddslib.from does, but to use it with an alias you need to nest in this way

Then (... () => {
  let expectedOddsValue
  let currentOddsValue = oddsSelectionElements.oddsButton().first().invoke("text")

  cy.get("@storedOddsValue").then(aliasValue => {

    let storedOddsValue = oddslib.from("fractional", aliasValue)

    switch (priceFormat) {
      ...
    }
    currentOddsValue.then((oddsValue) => {
      expect(oddsValue.trim()).equals(expectedOddsValue);
    });

  })   // end of cy.get("@storedOddsValue")
})

Because cy.get("@storedOddsValue") is asynchronous, and the switch() runs before it gives it's value.

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!