cypress cy.tick 在 cypress 组件测试中不起作用

me-*_*-me 3 cypress cypress-component-test-runner

有没有人成功地让 cy.tick() 在 cypress 组件测试中工作。cy.clock() 会停止时间,但在 cypress 组件测试中,tick 不会将其向前移动。如果有人能够做到这一点,请举出简单的例子。

再说一次,这是在 cypress 组件测试中,而不是 e2n 测试中。
我还在 before() 方法中添加了时钟。

Fod*_*ody 5

您可以在此处找到示例组件LoadingIndicator和测试set-timeout-example。

我在新的 CRA 应用程序中运行了代码,测试loading-indicator.cy.jsx通过了。

使用的测试之一cy.tick()是

it('should render loading indicator (mocks clock)', () => {
  cy.clock()
  mount(
    <LoadingIndicator isLoading={true}>
      <div>ahoy!</div>
    </LoadingIndicator>,
  )

  // force 2 seconds to pass instantly
  // and component's setTimeout to fire
  cy.tick(2010)

  cy.contains('loading...', 
    { timeout: 100 }               // fail if loader not displayed quickly
  ).should('be.visible')
})
Run Code Online (Sandbox Code Playgroud)

也许您的应用程序不使用受支持的本机计时器功能之一?