Skip to content Skip to sidebar Skip to footer

Obtaining $httpbackend In Qunit Tests

I am writing QUnit tests for an Angular controller. In the setup function of module, I have written the following statements to get an object of $httpBackend: var injector = angul

Solution 1:

I asked Scott Allen about this issue and he replied me with a JSFiddle that solves the issue. He stated that the following decorator is essential when we use $httpBackend or any other mock defined in angular-mocks.js in QUnit tests:

$provide.decorator('$httpBackend', angular.mock.e2e.$httpBackendDecorator);

I used this approach in a sample application and blogged my learning: http://sravi-kiran.blogspot.com/2013/06/UnitTestingAngularJsControllerUsingQUnitAndSinon.html

Solution 2:

You must setup angular to use the $httpBackend from angular-mocks.js Which contains the expectGET method.

But according to the docs it's "Only available with jasmine."

Post a Comment for "Obtaining $httpbackend In Qunit Tests"