1

I am testing an api which already has a callback inside a callback at the end of the function. I want to wrap this in a test to verify the object is correct but this doesn't seem to be working. callbackEnd() gets called but that's it.

In the library on a script load success:

function callback() {
  // populate gpt object
  if(typeof callbackEnd === 'function') {
    callbackEnd();
  }
}

Mocha.js test:

"use strict";
(function() {

  describe("Callback Success", function() {
    function callbackEnd() {

      console.log('callbackEnd() called');

      it('GPT returned advars', function() {
        expect(Object.keys(someobj).length).to.beGreaterThan(0);
        console.log('GPT loaded successfully, ' + Object.keys(someobj).length);
      });

    }
  });

})();
user1572796
  • 1,057
  • 2
  • 21
  • 46
  • Are you sure that the callbackEnd() declared on the mocha test is executed or is the callbackEnd coming from other place? (Because the callbackEnd in the mocha test is in a iife and i think it cant be acceded outside of that scope. – ecarrizo Jun 18 '15 at 22:59
  • yeah function callbackEnd() gets executed but the it() doesn't get executed. I'm sure its some sort of scope issue but not sure how to set this up – user1572796 Jun 18 '15 at 23:04

1 Answers1

0

There it goes, describe -> it -> custom callback function -> done();

 "use strict";
(function() {

  describe("Callback Success", function() {

      it('GPT returned advars', function(done) {

        function callbackEnd() {
          expect(Object.keys(someobj).length).to.not.equal(0);
          console.log('GPT loaded successfully, ' + Object.keys(someobj).length);
          done();
        }

      });
  });
})();
user1572796
  • 1,057
  • 2
  • 21
  • 46