1

I have an angular module called 'widgets'. Here is it's signature being used in my app:

var app = angular.module('widgets', [
    'widget.Panel',
    'widget.List',
    'services'
]);

I also have a controller being created off of app:

app.controller('clientListController', ['$scope', '$http', 'ServiceProvider', function ($scope, $http, ServiceProvider) {

I'm trying to write a unit test for 'clientListController'. Here is what I've done:

describe('clientListController', function () {
    var ctrl, scope;

    beforeEach(angular.module('widgets'));
    beforeEach(inject(function ($rootScope, $controller) {
        scope = $rootScope.$new();
        ctrl = $controller('clientListController', { $scope: scope });
    }));

    it("should define openClient function", function () {
        expect(scope.openClient).toBeDefined();
    });
});

When I try to run the tests, I get an error:

Error: Argument 'clientListController' is not a function, got undefined 

Is there something wrong with how I've written the test? How come clientListController isn't defined? Does it have something to do with the dependencies?

0

1 Answer 1

1

Use beforeEach(module('widgets')) or beforeEach(angular.mock.module('widgets')). You need to set a module for angular-mocks to work from. angular.mock.module gets assigned to window.module for convenience. Your code is just getting the module from angular and not setting it for angular-mocks to use.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.