I got a controller to be tested. Controller file is as :

'use strict';

angular.module('selfCareHub')

.controller('MainController', ['$rootScope', '$scope', '$state','$http',
'$stateParams', function ($rootScope, $scope, $state,$http,$stateParams) {

$http.get('http://localhost:8080/self-care-hub-grails/main/index.json'
).success(function(data){

$scope.conditions=data;

console.log(data);

});

$scope.$on("$destroy", function() {

});

}]);


My test file is :

 describe("Test for the main controller", function(){

var mockScope,controller,backend, url;

beforeEach(angular.mock.module("selfCareHub"));

beforeEach(angular.mock.inject(function($httpBackend){

backend=$httpBackend;

url="http://localhost:8080/self-care-hub-grails/main/index.json";;

backend.expect("GET",url).respond(

[

{

"items":[{"fields":{"name":"Anxiety"}},

          {"fields":{"name":"Breathing"}},

          {"fields":{"name":"Pain"}}, ]

}

]

);

}));

beforeEach(angular.mock.inject(function($controller,$rootScope,$http){

mockScope=$rootScope.$new();

$controller("MainController",{

$scope: mockScope,

$http: $http

});

backend.flush();

}));


it("Makes an Ajax request", function(){

backend.verifyNoOutstandingExpectation();

});

  it("Processes the data", function () {

        expect(mockScope.conditions).toBeDefined();

        expect(mockScope.conditions.length).toEqual(3);

});

 

  it("delivers the set of conditions", function () {

        expect(mockScope.conditions.items[0].fields.name).toEqual("Anxiety"
);

        expect(mockScope.conditions.items[1].fields.name).toEqual(
"Breathing");

        expect(mockScope.conditions.items[2].fields.name).toEqual("Pain");

  });

});


But I am getting an error as following: 

Error: Unexpected request: GET assets/conditions.html

No more request expected

My backend is a grails server which responds with a json object on getting 
this url:  

"http://localhost:8080/self-care-hub-grails/main/index.json";


Can somebody please help me:


                        

-- 
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