jeudi 23 avril 2015

$httpBackend returns empty object (Expected Object({ }) to equal )

I am new to Unit Testing, and am trying to test a service, using $httpBackend.

Here's some code i have:

beforeEach(inject(function($controller, $httpBackend){
   $httpBackend.when('GET', 'some/url').respond([{},{},{}])
      controller = $controller("AssessmentTheme", {config: config})
}))
....
beforeEach(inject(function($httpBackend){
    $httpBackend.flush();
}))

it('shoud do something', function(){
   expect(controller.config).toEqual([{},{},{}]);
})

I have tried to put all sorts of different things into the response, but karma keeps failing, with the following message:

Expected Object({  }) to equal [ Object({  }), Object({  }), Object({  }) ]

I just can't figure out how to make the test to actually use the response coming from $httpBackend()

Is there anyone who see my problem and can lead me towards a solution?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire