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

294
Views
What testing approach should I use?

I am testing a very complex quoting tool where I need to test discount margin price and discount price. Lets say price in catalog is 100$ And a partner is getting 25% discount, then partner price is 75$

Should I test like this -> cy.get(partnerPriceField)/should('have.value', 75)

OR -> cy.get(partner PriceField)/should('have.value', catalogPrice * (1-discount/100))

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

0

cy.get(partnerPriceField).should('have.value', 75) is preferred for e2e tests.

The job of testing the calculation falls to unit tests, which are close to the source code so test can be changed if/when the src calculation changes.

The job of e2e test is to make sure that given some input data the page shows the output data (black box).

Preferably input and output are supplied in a fixture table that's easily adjusted when the calculation is revised.

about 4 years ago · Juan Pablo Isaza Report

0

You can pass a regex with .contains() and followed by an assertion to check the value is visible.

const fullPrice = 100
const discount = .25
const discountPrice = fullPrice * discount
const regexMatcher = new RegExp(`$${discountPrice}`) // equals /\$75/

cy.contains('.selector-containing-price-text', regexMatcher)
  .should('be.visible')
about 4 years ago · Juan Pablo Isaza Report

0

I would suggest you go with the second option because in that case if in future the catalog price or discount value changes, you don't have to change the logic because it's generic. Having said that, for the second option to work you have to first change the catalogPrice and discount to numbers then after calculation, you have to convert the final answer to a string and then do the final assertion, something like this:

cy.get('partner PriceField').should(
  'have.value',
  (+catalogPrice * (1 - +discount / 100)).toString()
)

This is how your calculation looks like:

JS calculation

Also in case, if your catalogPrice is coming as 100$ and discount is coming as 25%, just add .replace(/\D/g,'') to remove % and $. Then in this case your assertion will look like this:

cy.get('partner PriceField').should(
  'have.value',
  (
    +catalogPrice.replace(/\D/g, '') *
    (1 - +discount.replace(/\D/g, '') / 100)
  ).toString()
)

Your calculation would look like this:

calculation 2

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!