vendredi 29 juillet 2016

Test local scope variable in anonymous asynchronous function

after scouring the internet for examples and tutorials and documentation on testing with jasmine and still not able to make things work, I turn to stackoverflow for help:

I have the following function in my Angular JS controller:

function setupMenuPopover() {
      $ionicPopover.fromTemplateUrl('views/menu-popover.html', {
          scope: $scope
        }).then(function (popover) {
          vm.menuPopover = popover;
        });
    }

How can I test that the menuPopover variable is defined? (Should I test this?)

Currently I have something like the following, using jasmine 2.4 (& Karma):

describe('testing the menuPopover', function () {
  var menuPop;
  beforeEach(function (done) {
    HomeController.menuPopover = HomeController.setupMenuPopover();
    setTimeout(function () {
      done();
    }, 3000);
  });

  it('this.menuPopover should be initialized and defined', function (done) {
    expect(HomeController.menuPopover).toBeDefined();
    done();
  });
});

But it's still undefined..

Any help is much appreciated. Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire