繁体   English   中英

摩卡/柴-超时,确保诺言得以解决

[英]Mocha / Chai - Timeout, ensuring promise resolves

关于这个问题有数千个问题,我想我已经阅读了所有问题,但是我仍然不明白为什么以下内容不起作用。

此代码在本地执行没有问题。 在TravisCI上运行时-失败,并确保将done()称为错误。

it('Function oLab.GetObjects & oLab.Deploy', (done) => {
    var l = new oLab('1')
    l.getObjects().then(function(data){
        console.log(data);
        expect(data.length).to.above(0);
        //There is a bunch of other code in here commented out since this alone doesn't work.  
    })
    .then(() => done(), done)
    .catch(function (err) {     }); // Not executed
});

我知道getObjects函数失败了:

this.getObjects = function () {
    console.log("oLab getObjects function");
    return getResources(this.id);
}

该调用getResources:

function getResources(labID){
    return db.any('select * from lab_resources where lab_id = ' + labID).then(function(data){
        var resources = [];
        //Modifies the resources and returns the list.  Logging this displays the correct data.  
        return resources;
    })
    .catch(function (err) {     }); // Not executed

}

问题:

  1. 我阅读了此博客,并根据此博客将其添加(完成)到我的函数中,因为我认为自己应允了。 如果它是嵌套的,我是否应退还保证书? IE浏览器,我称其为getObjects,其次为getResources。 getResources返回一个数据库查询,但是在其中-返回一个值。 这是否意味着我要向调用函数返回一个Promise或值? 我认为它会返回承诺,因为不会立即执行承诺。
  2. 在getObjects中,我试图设置oLab的属性。 我应该在getObjects函数中设置该属性还是应该将其返回给调用方法,然后更改oLab的属性?

事实证明Travis CI无法访问我请求的数据库,因此数据库连接设置失败。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM