Skip to content

Cypress throws an assertion error but the result is correct #28460

Discussion options

You must be logged in to vote

Ah, ok, it´s like this:

Solution 1: Convert valueOfCalculation to a string

cy.get('#specific_id').then(function (calculation) {
  var valueOfCalculation = value1 - value2;
  // Convert the numeric value to a string before comparison
  expect(valueOfCalculation.toString()).to.equal(value3);
});

Solution 2: Convert value3 to a number

cy.get('#specific_id').then(function (calculation) {
  var valueOfCalculation = value1 - value2;
  // Convert the string value to a number before comparison
  expect(valueOfCalculation).to.equal(Number(value3));
});

Sorry for interruption :-)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by thepixelhead
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant