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 9276263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:48:18+00:00 2026-06-18T16:48:18+00:00

Everything on the app works fine, so its just my tests that are syntactically

  • 0

Everything on the app works fine, so its just my tests that are syntactically incorrect. Here’s a truncated version of what I’m working with. The names and locations have been changed to protect the innocent.

var m;

m = angular.module('CustomService', []);

window.CustomService = m.factory("CustomService", function($rootScope) {
  var sharedService;
  sharedService = {};
  sharedService.broadcastItem = function() {
    return console.log('Works!');
  };
  return sharedService;
});

window.MyCtrl = function($scope, $location, CustomService) {
  this.$inject = ['$scope', 'CustomService'];
  return $scope.test_method = function(date) {
    return CustomService.broadcastItem(date);
  };
};

describe('MyCtrl', function() {
  beforeEach(inject(function($rootScope, $controller, $location) {
    this.scope = $rootScope.$new;
    return this.controller = $controller(MyCtrl, {
      $scope: this.scope,
      $location: $location,
      CustomService: CustomService
    });
  }));
  return it('tests my method', function() {
    return this.scope.test_method('10-1984');
  });
});

And that final line returns :

TypeError: Object #<Object> has no method 'test_method'

Strange! Because my entire app works and thrives off the fact that that method works flawlessly. So it must be that I’m not properly injecting this module ( guessing! ).

  • 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-18T16:48:19+00:00Added an answer on June 18, 2026 at 4:48 pm

    There were number of things going on in your code and test, really so it is a bit hard to list them all. It is kind of hard to completely help with this test as you didn’t provide implementation to be tested (apart from the log) so I’ve stubbed something I think you would like to do and test.

    So, here is the test:

    describe('MyCtrl', function() {
    
      var scope, controller;
      beforeEach(module('CustomService'));
      beforeEach(inject(function($rootScope, $controller, $location) {
        scope = $rootScope.$new();
        controller = $controller('MyCtrl', {
          $scope: scope
        });
      }));
    
      it('tests my method', function() {
        scope.test_method('10-1984');
        expect(scope.brodcastedValue).toEqual('10-1984');
      });
    });
    

    The issues in the test were:

    • Incorrect scope creation ($new() is a method not a property
    • Lack of reference to a module: beforeEach(module('CustomService'));
    • Too many dependencies specified to a controller

    I’ve also modified the code itself to make the test pass:

    m.factory("CustomService", function($rootScope) {
      var sharedService;
      sharedService = {};
      sharedService.broadcastItem = function(date) {
        $rootScope.$broadcast('works', date);
      };
      return sharedService;
    });
    
    m.controller('MyCtrl', function($scope, $location, CustomService) {
    
      $scope.test_method = function(date) {
        CustomService.broadcastItem(date);
      };
    
      $scope.$on('works', function(event, date){
        $scope.brodcastedValue = date;
      });
    });
    

    Not sure if the above was your intention or not. Anyway, it looks like the code was converted from CoffeScript or something (full of return and this) so I’m not sure I get it right.

    Finally, a working plunk, hopefully this one will clarify all the details:
    http://plnkr.co/edit/x2Jjvm8zwwaLZYV9aLfo?p=preview

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

Sidebar

Related Questions

I developed an iPhone application using PhoneGap everything works fine, I sent the app
I have developed a web app using a webservice. Everything works fine in the
I wrote a C app that uses the PCRE library. Everything works on my
I'm working on a localized app and everything is working fine. The problem is
So I have an MVC 2 App running on Windows Azure. Everything works fine,
i am developing an app which has a evernote integration,everything works perfect but my
I'm localizing a WPF app using the LocBaml method. Everything works great for UI
I implement notifications in my IOS app, and I use customized sounds. Everything works
Everything's fine building in xcode and testing the app until I built in for
I have a Rails app that does everything I need it to do via

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.