【问题标题】:Last test at cypress is showing all assertionscypress 的最后一次测试显示所有断言
【发布时间】:2020-06-02 20:03:30
【问题描述】:

我刚开始使用 Cypress 作为自动化测试框架。目前我正在尝试使用赛普拉斯在基于 GraphQL 的 API 中自动化测试。我可以调用 api,毫无问题地获得响应,但是当我尝试使用“Assert.Equal(“response variable”,“expected msg”)”进行断言时,我的断言只出现在最后的描述中,尽管我的所有描述都在以 Test.js 为例 两个用断言描述,但只有最后一个节目

【问题讨论】:

  • 您能与我们分享您的代码吗?能够查看您正在运行的测试文件会有所帮助
  • 这里有我说的代码ctxt.io/2/AABANaYoFA
  • Offtopic:但为什么会有人使用非英语界面/键构建 API?

标签: node.js testing graphql cypress assertion


【解决方案1】:

测试是异步运行的,这使得 testrunner 比实际返回结果更快。

看看他们的 async recipies .. async/await 或者至少返回一个 Promise 可能是你的朋友: https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/unit-testing__application-code/async-methods.js

如果您不喜欢async/await,您的最后一次测试可能如下所示:

it('ConsultaCredenciado por cnpj',function(){
  return new Promise((resolve, _) => {
    var client = require('graphql-client')({
        url: 'apiURL/credenciadosplant/',
        headers: {
          Authorization: 'Bearer ' + token
        }
      })

    client.query(
        `query{
            consultarCredenciado(cnpj :"123456456")
            {
              IdCredenciado
              CNPJ
              IdCredenciadoLegado
              Email
            }
          }`,function(req,res){
          if(res.status === 401){
              throw new error('Not Authorized')
          }
      }).then(function(res){
        console.log(res)
        expect(res.data.consultarCredenciado[0].Email).to.equal('aaaaa@aaaaaa.com')
        resolve(true);
    })
  });
}); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    • 2019-05-30
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多