Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

283
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda