Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8729641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:52:04+00:00 2026-06-13T08:52:04+00:00

I am attempting to test an AngularJS controller with a Jasmine unit test spec

  • 0

I am attempting to test an AngularJS controller with a Jasmine unit test spec file. My approach is to use $httpBacked, in the following test:

describe('SubmissionsController', function() {
    var minimal_mock_response = [ { id: 1 } ]; 
    var scope, routeParams, $httpBackend; 

    beforeEach(module('submissionServices'));

    beforeEach(inject(function($_httpBackend_, $rootScope) {
        scope = $rootScope.$new();  
        $httpBackend = $_httpBackend_;
        $httpBackend.expectGET('/submissions').respond(minimal_mock_response);
        routeParams = {};
    }));

    it('passes a trivial test', function() {
        expect(true).toBe(true);
    });
});

I inserted the expect(true).toBe(true) just to get the test to execute and fail, even though it does not touch the angular controller. When I I attempt to run the test with jasmine-headless-webkit, I receive the following error:

jasmine-headless-webkit spec/javascripts/SubmissionsControllerSpec.js

Running Jasmine specs...
F
FAIL: 1 test, 1 failure, 0.011 secs.

Submissions controllers SubmissionsController passes a trivial test.     (XXX/spec/javascripts/SubmissionsControllerSpec.js:18)
Error: Unknown provider: $_httpBackend_Provider <- $_httpBackend_

Test ordering seed: --seed 9254 

Are there any hints on how I can correct this error and make the trivial test execute?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:52:05+00:00Added an answer on June 13, 2026 at 8:52 am

    I believe this is because you’re injecting the wrong service. It doesn’t know what $_httpBackend_ is. You should be able to just do this:

    beforeEach(inject(function($httpBackend, $rootScope) {
        scope = $rootScope.$new();  
        $httpBackend.expectGET('/submissions').respond(minimal_mock_response);
        routeParams = {};
    }));
    

    If you want to get a reference to the $httpBackend service once and store that as $httpBackend, ghiden’s answer is the way to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to add a Test Settings file to my Unit Tests project in
I'm attempting to test a class which makes use of the rails configuration file.
I am attempting to test the Index action of a controller. The action uses
I'm using Spring MVC 3.1 and I am attempting to test a controller class
I'm attempting a simple test of binary file I/O using the STL copy algorithm
I'm attempting to unit test some code using NUnit. I have a method: public
I am attempting to test simple UI with the following test case, The main
While attempting to access a test portal, I'm encountering the following problem while using
I'm attempting to make a quick test to synchronize a file to iCloud. This
I'm attempting to get the following site to work: The Test logo appears properly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.