用柏树取消请求

发布于 2025-02-06 13:31:37 字数 268 浏览 0 评论 0原文

我正在寻找一种期望与柏树取消请求的方法。有什么想法吗? :) 如果用户发送太多请求,我要取消以前的请求,并且我想对其进行测试。 我试图用别名拦截发布请求,计数的请求,...

“

I'm looking for a way to expect a canceled request with cypress. Any idea? :)
I cancel the previous requests if the user sends too many requests and I want to test it.
I tried to intercept POST requests with the alias, counted requests,...

image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2025-02-13 13:31:37

命令正在以与JavaScript异步工作的队列运行。

为了在队列运行后断言计数器值,请将断言包含在中。然后()

let counter;

When('I click on the refresh button', () => {
  cy.wait(2000); 
  cy.window().then(window => window.msw.worker.stop()); 
  cy.intercept('POST', 'myApi', {
    body: { 
      items: [] 
    } 
  }).as('search'); 

  client.SearchBar.refresh(); 

  cy.wait('@search').then(interceptor > { 
    counter++; 
    console.log('Interceptor', interceptor.request,
      'Response', interceptor?.response,
      '\nCounter', counter) 
  }); 

  cy.then(() => {
    expect(counter).to.be.not.eq(2); 
  })
  ...
})

Commands are running on a queue which works asynchronously from the javascript.

To assert the counter value after the queue has run, wrap the assertion in a .then().

let counter;

When('I click on the refresh button', () => {
  cy.wait(2000); 
  cy.window().then(window => window.msw.worker.stop()); 
  cy.intercept('POST', 'myApi', {
    body: { 
      items: [] 
    } 
  }).as('search'); 

  client.SearchBar.refresh(); 

  cy.wait('@search').then(interceptor > { 
    counter++; 
    console.log('Interceptor', interceptor.request,
      'Response', interceptor?.response,
      '\nCounter', counter) 
  }); 

  cy.then(() => {
    expect(counter).to.be.not.eq(2); 
  })
  ...
})
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文