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

156
Views
How to get the value from other method/function in JavaScript

I am new to Cypress and JavaScript, Please help me with this query to understand more

I have to automate a website using cypress to validate the EMI value.

Below is my .js code where I need to implement the EMI calculator logic and need to pass it to another method ('it' block in cypress). 'it' block will get the value from the website and should validate with the EMI logic which I return in code EMILogic() method.

EMILogic() will return a value (emi) and I am passing this value in line cy.get('#emi').should('have.text', EMIdata.emi) but while executing the code I am getting assertion error in cypress as Timed out retrying after 4000ms: expected '<span#emi>' to have text undefined, but the text was '925.11'

describe('EMI Calculation', function () {

 class abc{
 EMILogic() {

    const amount = 20000;
    const rate = 5;
    const month = 2;
let emi;
rate = rate/(12*100);
period = period*12;

emi = (amount*rate*Math.pow(1+rate, month))/(Math.pow(1+rate, month)-1);
return emi

   }
   }

Below is the code where I need to pass the value of emi from above class

    it('EMI calculator', function () {
    const EMIdata = new abc();

    cy.visit('emi-calculator.html')
    cy.get('.MR15').click()
    cy.get('#emi').should('have.text', EMIdata.emi)

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

0

Problem:

const EMIdata = new abc();

This line of code means EMIdata is an object of class abc. there is no member variable named emi on class abc. hence you are getting an undefined when using EMIdata.emi.

Solution:

As your member function EMILogic returns the emi value. Instead of EMIdata.emi you can call EMILogic using EMIdata.EMILogic() inside your should function.

cy.get('#emi').should('have.text', EMIdata.EMILogic())
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!