0

I am trying to assert the value's in an array. At this moment I made it to assert just the length:

cy.get('@UrlAndAppendices')
  .its('request.body.correctionInstructionAppendices')
  .should('have.length', 2)

What is the best way to compare this? I can make an deep equal with a fixture. But I dont think that this would be the cleanest solution for assertin just 2 value's in a array.

Result in cypress

1

2 Answers 2

1

For something as simple as two items, best readability (more concise code) is to assert inline.

Length of 2 is implied in the deep.eq check (i.e 1 item would fail, and 3 items would fail).

cy.get('@UrlAndAppendices')
  .its('request.body.correctionInstructionAppendices')
  .should('deep.eq', ['abc', '123'])                     

or this way

cy.get('@UrlAndAppendices')
  .its('request.body.correctionInstructionAppendices')
  .should('include', 'abc')                     
  .and('include', '123')                     
Sign up to request clarification or add additional context in comments.

Comments

0

If the values will not change in the array then you can create a variable to check against.

const arrValues = [2, 3]
cy.get('@UrlAndAppendices')
  .its('request.body.correctionInstructionAppendices')
  .should('have.length', 2)
  .and('deep.equal', arrValues)

Here is an example with using a fixture instead.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.