【问题标题】:Cypress stubbing with .intercept() and fixture赛普拉斯存根与 .intercept() 和夹具
【发布时间】:2020-12-08 16:28:48
【问题描述】:

我正在尝试存根来自 API 的响应。按照赛普拉斯文档,我找到了这个:

cy.intercept('GET', '/v1/answers', { fixture: 'answers.json' }).as(
  'getAnswers'
)

cy.wait('@getAnswers').then(console.log)

console.log 产生正确的响应。

但是,UI 组件似乎并未使用此数据。相反,组件中的数据返回为空。在 Cypress 中正确使用拦截和固定装置有什么遗漏吗?

【问题讨论】:

    标签: cypress


    【解决方案1】:

    对于遇到此问题的任何人。在 Cypress 应用程序的浏览器控制台中,我注意到一个 CORS 错误,需要添加 Access-Control-Allow-Origin

    cy.intercept('GET', '/v1/answers', {
      fixture: 'answers.json',
      headers: {
        'Access-Control-Allow-Origin': '*',  // <== This fixed it 
      },
    }).as('getAnswers')
    

    :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 2020-12-23
      相关资源
      最近更新 更多