mercredi 6 mai 2015

Unit-test issue in my app

I am having an issue loading a $resource object in my case.

I have something in parent controller like

$scope.data = Product.$query();

then in the child controller, I have

$scope.data.$promise.then(function(product){
     console.log(data);
})

My factory

angular.module('testApp').factory('Product', ['$resource', function ($resource) {
    return $resource('/api/product');
}]);

The reason I put Product.$query() in the parent controller is because I want it to be shard and use in different child controller.

My test file is like following

describe('Product test ', function () {
    var $httpBackend, childCtrl,  scope;

    beforeEach(module('testApp', function($provide) {
        $provide.value('$log', console);
    }));

    beforeEach(inject(function (_$controller_, _$httpBackend_, _$rootScope_) {
        scope = _$rootScope_.$new();
        $rootScope = _$rootScope_;
        $httpBackend = _$httpBackend_;

        childCtrl = _$controller_('childCtrl', {
            $scope: scope
        });
    }));

    describe('some test', function() {
        it('some test here', function(){
             //codes...
        })
    })
});

When I run the test, I am getting

TypeError: 'undefined' is not an object (evaluating '$scope.data.$promise')

I am not sure what's going on here. Can someone help me about it? Thanks a lot

Aucun commentaire:

Enregistrer un commentaire