按照对多个属性对象的承诺检查柴 [英] check chai as promised on multiple properties object

查看:113
本文介绍了按照对多个属性对象的承诺检查柴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个方法可以将数据和URL一起返回给我,因此return对象具有url和body作为两个属性.

hello I have a method which returns me data along with URL , so return object has url and body as two properties.

  return new Promise(function(resolve,reject)
    {
      request(url, function (error, response, body) {
        if(error)
              reject(error);
          else
          {
              if(response.statusCode ==200)
                    resolve( { "url" :url , "body" : body});
                else
                    reject("error while getting response from " + url);
          }
      });

    });

我应该如何在柴上进行测试

How should I test this in Chai- as promised

它可用于1个物业.

it("get data from correct url", function(){
   return expect (httphelper.getWebPageContent(config.WebUrl))
   .to.eventually.have.property('url')
});

如果我包含其他属性,它将在先前的属性内搜索.

if I include other property it searches inside previous property.

it("get data from correct url", function(){
   return expect (httphelper.getWebPageContent(config.WebUrl))
   .to.eventually.have.property('url')
   .and.to.have.property('body')
});

AssertionError:预期" http://www.jsondiff.com/"具有属性"body" '

AssertionError: expected 'http://www.jsondiff.com/' to have property 'body'

我要去哪里错了?

推荐答案

创建具有预期属性的对象:

Create an object with the expected properties :

const expected = {
    url: "expected url",
    body: "expected body"
};

然后确保结果包含:

return expect(httphelper.getWebPageContent(config.WebUrl))
.fulfilled.and.eventually.include(expected);

这篇关于按照对多个属性对象的承诺检查柴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆