Hey All, 

I'm trying to get some tests but it is not working. I have a controller 
that calls a service 

var myCtrl = function($scope, someData) {

        $scope.someData = someData;
        someData.getCurrentQuestion();
        
    };
    return [ "$scope", 'someData',  myCtrl ];

I have a service that gets data from an $http 

var someData = function($http) {
        var Data = {
            getCurrentQuestion: getCurrentQuestion,
            
        };
        function getCurrentQuestion() {
            $http.get('PATH').success(function(data) {
                Data.questionId = data.questionId;
                Data.text = data.text;
                Data.kind = data.kind;
            })

        }
        return Survey
    };
    return ['$http', someData]

Now from the following test that is not working, how would i fake data for 
the $http request. This is my non-working code. I would really appreciate 
your help.  

describe('myCtrl', function() {
        var $scope,
            mockService,
            firstQuestion = {
                "questionId": "gender",
                "text": "blah",
                "kind": true,
            };

        beforeEach(module('myModule'));
        beforeEach(inject(function($rootScope, $controller,_someData_, $q) {
            $scope = $rootScope.$new();
            mockService = _someData_;
            spyOn(mockService, 'getCurrentQuestion')
                .andCallFake(function() {
                    return firstQuestion
                });
            $controller('myCtrl', {$scope: $scope, someData: mockService})
        }));

        beforeEach(function(){
            $scope.$digest();
        });



        describe('someService', function() {
            it('ensures test passes' , function() {
                expect($scope.someData. questionId).toBe('gender');
            });
            
            it(''ensures test passes'', function() {
                expect($scope.someData.kind).toBe(true);
            });

        })

    })

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to