Mocha / Chai - Timeout, ensuring promise resolves





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















There's several thousand questions on this and I think I've read all of them but I still don't understand why the following doesn't work.



Locally this code executes without an issue. When run on TravisCI - it fails with the ensure done() is being called error.



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
});


I know the getObjects function is failing:



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


which calls 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


}



Questions:




  1. I read this blog and based off of it added (done) to my functions as I think I return a promise. Do I return a promise if it is nested? IE I call getObjects followed by getResources. getResources returns a DB query but within that - there is a value returned. Does that mean I'm returning a promise or the value to the calling function? I thought it would return the promise as the promise wouldn't be executed immediately.

  2. Within getObjects, I'm trying to set a property of oLab. Should I set that property within the getObjects function or should I return that to my calling method and then alter the property of oLab?










share|improve this question























  • Having other people read this should be a good reminded why you should have good descriptive names for tests. I can't tell what you testing here with "Function oLab.GetObjects & oLab.Deploy". Using catch and the second callback to then is probably a mistake because you will intercept the error generated by a failing test.

    – Mark Meyer
    Nov 25 '18 at 1:48











  • @MarkMeyer I have logging in both catch statements and neither of them log thus I didn't think they were executing and why I left them off. I wrote a significantly more complicated test that I've stripped down to this as it was still failing the basic test in TravisCI. If I caught - and logged - the error on the inner function, why is it a bad idea to nest catch statements?

    – gbam
    Nov 25 '18 at 1:53











  • You are using both callbacks in then with then(done, done) The second call back is for errors. Unless you throw in the second call back catch() will never happen. It's much easier with mocha to leave done out of it and just return the promise.

    – Mark Meyer
    Nov 25 '18 at 2:00













  • @MarkMeyer I can understand the rationale for returning the promise however when return l.getObjects() - it timesout which is why I turned to done. I know l.getObjects returns a promise as if I set l.getObjects equal to a variable and log it, it shows promise. I started with returning the promises directly then turned to done() as I couldn't get it to work.

    – gbam
    Nov 25 '18 at 2:11













  • You need to make sure you remove done from it('Function oLab.GetObjects & oLab.Deploy', (done) . That's how it knows to look for a promise.

    – Mark Meyer
    Nov 25 '18 at 2:12


















0















There's several thousand questions on this and I think I've read all of them but I still don't understand why the following doesn't work.



Locally this code executes without an issue. When run on TravisCI - it fails with the ensure done() is being called error.



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
});


I know the getObjects function is failing:



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


which calls 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


}



Questions:




  1. I read this blog and based off of it added (done) to my functions as I think I return a promise. Do I return a promise if it is nested? IE I call getObjects followed by getResources. getResources returns a DB query but within that - there is a value returned. Does that mean I'm returning a promise or the value to the calling function? I thought it would return the promise as the promise wouldn't be executed immediately.

  2. Within getObjects, I'm trying to set a property of oLab. Should I set that property within the getObjects function or should I return that to my calling method and then alter the property of oLab?










share|improve this question























  • Having other people read this should be a good reminded why you should have good descriptive names for tests. I can't tell what you testing here with "Function oLab.GetObjects & oLab.Deploy". Using catch and the second callback to then is probably a mistake because you will intercept the error generated by a failing test.

    – Mark Meyer
    Nov 25 '18 at 1:48











  • @MarkMeyer I have logging in both catch statements and neither of them log thus I didn't think they were executing and why I left them off. I wrote a significantly more complicated test that I've stripped down to this as it was still failing the basic test in TravisCI. If I caught - and logged - the error on the inner function, why is it a bad idea to nest catch statements?

    – gbam
    Nov 25 '18 at 1:53











  • You are using both callbacks in then with then(done, done) The second call back is for errors. Unless you throw in the second call back catch() will never happen. It's much easier with mocha to leave done out of it and just return the promise.

    – Mark Meyer
    Nov 25 '18 at 2:00













  • @MarkMeyer I can understand the rationale for returning the promise however when return l.getObjects() - it timesout which is why I turned to done. I know l.getObjects returns a promise as if I set l.getObjects equal to a variable and log it, it shows promise. I started with returning the promises directly then turned to done() as I couldn't get it to work.

    – gbam
    Nov 25 '18 at 2:11













  • You need to make sure you remove done from it('Function oLab.GetObjects & oLab.Deploy', (done) . That's how it knows to look for a promise.

    – Mark Meyer
    Nov 25 '18 at 2:12














0












0








0








There's several thousand questions on this and I think I've read all of them but I still don't understand why the following doesn't work.



Locally this code executes without an issue. When run on TravisCI - it fails with the ensure done() is being called error.



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
});


I know the getObjects function is failing:



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


which calls 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


}



Questions:




  1. I read this blog and based off of it added (done) to my functions as I think I return a promise. Do I return a promise if it is nested? IE I call getObjects followed by getResources. getResources returns a DB query but within that - there is a value returned. Does that mean I'm returning a promise or the value to the calling function? I thought it would return the promise as the promise wouldn't be executed immediately.

  2. Within getObjects, I'm trying to set a property of oLab. Should I set that property within the getObjects function or should I return that to my calling method and then alter the property of oLab?










share|improve this question














There's several thousand questions on this and I think I've read all of them but I still don't understand why the following doesn't work.



Locally this code executes without an issue. When run on TravisCI - it fails with the ensure done() is being called error.



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
});


I know the getObjects function is failing:



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


which calls 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


}



Questions:




  1. I read this blog and based off of it added (done) to my functions as I think I return a promise. Do I return a promise if it is nested? IE I call getObjects followed by getResources. getResources returns a DB query but within that - there is a value returned. Does that mean I'm returning a promise or the value to the calling function? I thought it would return the promise as the promise wouldn't be executed immediately.

  2. Within getObjects, I'm trying to set a property of oLab. Should I set that property within the getObjects function or should I return that to my calling method and then alter the property of oLab?







javascript node.js mocha chai






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 1:41









gbamgbam

69941129




69941129













  • Having other people read this should be a good reminded why you should have good descriptive names for tests. I can't tell what you testing here with "Function oLab.GetObjects & oLab.Deploy". Using catch and the second callback to then is probably a mistake because you will intercept the error generated by a failing test.

    – Mark Meyer
    Nov 25 '18 at 1:48











  • @MarkMeyer I have logging in both catch statements and neither of them log thus I didn't think they were executing and why I left them off. I wrote a significantly more complicated test that I've stripped down to this as it was still failing the basic test in TravisCI. If I caught - and logged - the error on the inner function, why is it a bad idea to nest catch statements?

    – gbam
    Nov 25 '18 at 1:53











  • You are using both callbacks in then with then(done, done) The second call back is for errors. Unless you throw in the second call back catch() will never happen. It's much easier with mocha to leave done out of it and just return the promise.

    – Mark Meyer
    Nov 25 '18 at 2:00













  • @MarkMeyer I can understand the rationale for returning the promise however when return l.getObjects() - it timesout which is why I turned to done. I know l.getObjects returns a promise as if I set l.getObjects equal to a variable and log it, it shows promise. I started with returning the promises directly then turned to done() as I couldn't get it to work.

    – gbam
    Nov 25 '18 at 2:11













  • You need to make sure you remove done from it('Function oLab.GetObjects & oLab.Deploy', (done) . That's how it knows to look for a promise.

    – Mark Meyer
    Nov 25 '18 at 2:12



















  • Having other people read this should be a good reminded why you should have good descriptive names for tests. I can't tell what you testing here with "Function oLab.GetObjects & oLab.Deploy". Using catch and the second callback to then is probably a mistake because you will intercept the error generated by a failing test.

    – Mark Meyer
    Nov 25 '18 at 1:48











  • @MarkMeyer I have logging in both catch statements and neither of them log thus I didn't think they were executing and why I left them off. I wrote a significantly more complicated test that I've stripped down to this as it was still failing the basic test in TravisCI. If I caught - and logged - the error on the inner function, why is it a bad idea to nest catch statements?

    – gbam
    Nov 25 '18 at 1:53











  • You are using both callbacks in then with then(done, done) The second call back is for errors. Unless you throw in the second call back catch() will never happen. It's much easier with mocha to leave done out of it and just return the promise.

    – Mark Meyer
    Nov 25 '18 at 2:00













  • @MarkMeyer I can understand the rationale for returning the promise however when return l.getObjects() - it timesout which is why I turned to done. I know l.getObjects returns a promise as if I set l.getObjects equal to a variable and log it, it shows promise. I started with returning the promises directly then turned to done() as I couldn't get it to work.

    – gbam
    Nov 25 '18 at 2:11













  • You need to make sure you remove done from it('Function oLab.GetObjects & oLab.Deploy', (done) . That's how it knows to look for a promise.

    – Mark Meyer
    Nov 25 '18 at 2:12

















Having other people read this should be a good reminded why you should have good descriptive names for tests. I can't tell what you testing here with "Function oLab.GetObjects & oLab.Deploy". Using catch and the second callback to then is probably a mistake because you will intercept the error generated by a failing test.

– Mark Meyer
Nov 25 '18 at 1:48





Having other people read this should be a good reminded why you should have good descriptive names for tests. I can't tell what you testing here with "Function oLab.GetObjects & oLab.Deploy". Using catch and the second callback to then is probably a mistake because you will intercept the error generated by a failing test.

– Mark Meyer
Nov 25 '18 at 1:48













@MarkMeyer I have logging in both catch statements and neither of them log thus I didn't think they were executing and why I left them off. I wrote a significantly more complicated test that I've stripped down to this as it was still failing the basic test in TravisCI. If I caught - and logged - the error on the inner function, why is it a bad idea to nest catch statements?

– gbam
Nov 25 '18 at 1:53





@MarkMeyer I have logging in both catch statements and neither of them log thus I didn't think they were executing and why I left them off. I wrote a significantly more complicated test that I've stripped down to this as it was still failing the basic test in TravisCI. If I caught - and logged - the error on the inner function, why is it a bad idea to nest catch statements?

– gbam
Nov 25 '18 at 1:53













You are using both callbacks in then with then(done, done) The second call back is for errors. Unless you throw in the second call back catch() will never happen. It's much easier with mocha to leave done out of it and just return the promise.

– Mark Meyer
Nov 25 '18 at 2:00







You are using both callbacks in then with then(done, done) The second call back is for errors. Unless you throw in the second call back catch() will never happen. It's much easier with mocha to leave done out of it and just return the promise.

– Mark Meyer
Nov 25 '18 at 2:00















@MarkMeyer I can understand the rationale for returning the promise however when return l.getObjects() - it timesout which is why I turned to done. I know l.getObjects returns a promise as if I set l.getObjects equal to a variable and log it, it shows promise. I started with returning the promises directly then turned to done() as I couldn't get it to work.

– gbam
Nov 25 '18 at 2:11







@MarkMeyer I can understand the rationale for returning the promise however when return l.getObjects() - it timesout which is why I turned to done. I know l.getObjects returns a promise as if I set l.getObjects equal to a variable and log it, it shows promise. I started with returning the promises directly then turned to done() as I couldn't get it to work.

– gbam
Nov 25 '18 at 2:11















You need to make sure you remove done from it('Function oLab.GetObjects & oLab.Deploy', (done) . That's how it knows to look for a promise.

– Mark Meyer
Nov 25 '18 at 2:12





You need to make sure you remove done from it('Function oLab.GetObjects & oLab.Deploy', (done) . That's how it knows to look for a promise.

– Mark Meyer
Nov 25 '18 at 2:12












1 Answer
1






active

oldest

votes


















0














Turns out Travis CI wasn't able to access the Database I was requesting thus it was failing on the DB connection setup.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463969%2fmocha-chai-timeout-ensuring-promise-resolves%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Turns out Travis CI wasn't able to access the Database I was requesting thus it was failing on the DB connection setup.






    share|improve this answer




























      0














      Turns out Travis CI wasn't able to access the Database I was requesting thus it was failing on the DB connection setup.






      share|improve this answer


























        0












        0








        0







        Turns out Travis CI wasn't able to access the Database I was requesting thus it was failing on the DB connection setup.






        share|improve this answer













        Turns out Travis CI wasn't able to access the Database I was requesting thus it was failing on the DB connection setup.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 0:33









        gbamgbam

        69941129




        69941129
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463969%2fmocha-chai-timeout-ensuring-promise-resolves%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini