Timeout value for getAllByTestId?

866 views Asked by At
  cy.wait(20 * 1000);

  cy.getAllByTestId('test-field-one')
    .first()
    .within(() => cy.getByTestId('test-field-two'))
    .should('contain', 'test');

I'm currently using the above code, but I don't like the wait. I'd much rather prefer a timeout value. Does anyone know if this is possible in cypress?

1

There are 1 answers

0
user16695029 On

The getAll... functions can't really use a timeout.

The difference between { timeout: 20 * 1000 } and cy.wait(20 * 1000) is that timeout returns early when the condition it met.

But how many exactly is "all"?

The only way to do an "all" query is to wait the maximum time and return everything at that point in time - which is what you already do with explicit cy.wait().


Since you are using .first(), just switch to cy.getByTestId()

cy.getByTestId('test-field-one', { timeout: 20 * 1000 })
  .within(() => cy.getByTestId('test-field-two'))
  .should('contain', 'test')

Also note that

.should('contain', 'test')

is testing test-field-one not test-field-two because .within() does not pass on the inner value, it passes on the previous subject.