getAllByTestId 的超时值?

Kar*_*son -1 cypress cypress-testing-library

  cy.wait(20 * 1000);

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

我目前正在使用上面的代码,但我不喜欢等待。我更喜欢超时值。有谁知道这在柏树中是否可能?

use*_*029 5

这些getAll...函数不能真正使用超时。

{ timeout: 20 * 1000 }和之间的区别cy.wait(20 * 1000)在于,超时在满足条件时提前返回。

但到底有多少是“全部”呢?

执行“全部”查询的唯一方法是等待最长时间并返回该时间点的所有内容 - 这就是您已经使用显式执行的操作cy.wait()


既然您正在使用.first(),只需切换到cy.getByTestId()

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

另请注意

.should('contain', 'test')
Run Code Online (Sandbox Code Playgroud)

测试test-field-one不是test-field-two因为.within()没有传递内在价值,而是传递了前一个主题。