赛普拉斯存根“ECONNREFUSED 127.0.0.1:3000”错误

问题描述 投票:0回答:1

我有一个网站,使用“Apollo graphql 客户端”向服务器发送查询。 我已经设置了一个界面,当该网站无法连接到服务器时,即当收到错误“错误:连接ECONNREFUSED”时,将显示该界面。 我可以通过关闭服务器来手动测试这一点。 我想用赛普拉斯测试这是否正常工作。 我想使用 cy.intercept() 使其看起来像服务器不在线。 我该怎么做?

我读了https://docs.cypress.io/api/commands/intercept,我以为我会找到一个具体的例子,但我找不到。

api error-handling graphql cypress httpwebresponse
1个回答
0
投票

您可以看看这个线程网络自动化来模拟离线模式

要点是使用两个 RDP 调用来模拟网络离线。作为用户,您可以通过开发工具来执行此操作。 RDP 为您提供了等效的程序。

Cypress.automation('remote:debugger:protocol', {
  command: 'Network.enable',
})

Cypress.automation('remote:debugger:protocol', {
  command: 'Network.emulateNetworkConditions',
  params: {
    'offline': true,
    'latency': 0,
    'downloadThroughput': 0,
    'uploadThroughput': 0,
    'connectionType': 'none',
  },
})
© www.soinside.com 2019 - 2024. All rights reserved.