dimanche 27 mars 2016

How to unit test after callback of a controller in AngularJS?

I have a controller that has a callback inside:

angular.module('controllers').controller('headerController', headerController);

function headerController(headerService) {
    var self = this;

    headerService.getHeaderContentData()
        .then(function(response) {
            self.contentData = response.content;
        });
}

My problem is that I need to check the value of contentData in an unit test. The idea is when I call expect(ctrl.contentData).to.be.defined passes the test, but the value of ctrl.contentData is undefined. Is there a way to test this behavior (test the self.contentData when the callback occurs)?

Aucun commentaire:

Enregistrer un commentaire