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

  • SEARCH
  • Home
  • 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 8839381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:13:31+00:00 2026-06-14T10:13:31+00:00

Note: I’m writing everything in CoffeeScript I have a controller as follows: angular.module(‘myApp’).controller ‘MyController’,

  • 0

Note: I’m writing everything in CoffeeScript

I have a controller as follows:

angular.module('myApp').controller 'MyController', ($scope, $routeParams, Batch) ->
    $scope.$on '$routeChangeSuccess', () ->
        Batch.get {batchUuid: $routeParams.batchUuid}, (response) ->
            $scope.batch_id = response.id

The controller pulls in the Batch resource which is defined as follows:

angular.module('myApp').factory 'Batch', ($resource) ->
    $resource '/batches/:batchUuid', {}

I have a route for this as follows:

$routeProvider.when('/batches/:batchUuid',
    { templateUrl: 'batches-processing.html', controller: 'MyController' })

So:

  • You visit the route /batches/22
  • It uses MyController
  • It triggers $routeChangeSuccess
  • It calls get on the Batch resource witch the batchUuid from the route
  • It gets back a json response and assigns an id to $scope.batch_id

Now I want to test this so I have a unit test as follows:

describe 'Controllers', ->
    beforeEach module 'myApp'
        describe 'MyController', ->
            scope = {}
            ctrl= {}

            beforeEach inject ($rootScope, $controller, Batch, $httpBackend) ->
                scope = $rootScope.$new()
                ctrl = $controller('MyController', ($scope: scope))
                #I imagine I need to use either my injected Batch resource or the httpBackend to fake/expect the ajax call here

            it "Gets data from the resource and assigns it to scope", () ->
                #How on earth do I test this

I have seen people using $httpBackend.expect(‘/endpoint.json’).respond({id:1}) etc but I can’t do that. My resource URL relies on a batchUuid from the route. How can I simulate/fake/implement a test that will simulate a route change, trigger the $routeChangeSuccess, pass a routeParameter to the resource, do a get on the resource and test the result?

I’m pulling my hair out over this and angular docs don’t seem to cover it.

Thanks!

  • 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-14T10:13:32+00:00Added an answer on June 14, 2026 at 10:13 am

    You can make a fake routeParams and inject it into your controller.

    I use jasmine’s createSpy for my fakes, but that might be a bit overkill. There’s an example here that shows how to create and inject the fake routeParams.

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

Sidebar

Related Questions

NOTE: This is a followup to my question here. I have a program that
NOTE: I have read Routing From the Inside Out AND the Engine Yard blog
NOTE : I have edited my question because of my input data present in
NOTE: I have updated this since originally asking the question to reflect some of
Note that when I say client, I mean businesses or organizations that have signed
Note: To answer this question, you shouldn't have to know anything about Selenium or
note from N00B land again. I have read lots about sorting arrays - wanted
NOTE: This is an entire rewrite of the previous question. I have a model.
NOTE: Please, don't code it for me. I already have a home-rolled function to
Note: I've read this and its not quite what I'm looking for: I have

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.