Search code examples
javascriptweb-applicationsangularjsjasmine

Unknown provider: $rootscopeProvider <- $rootscope


I'm trying to inject $scope into a jasmine test, but get the exception

Unknown provider: $rootscopeProvider <- $rootscope

My Spec file is this:

describe("with data returned from NormDefinitions API", function () {
    const dummyData = [
        {"Id": 1, "Name": "Name 1", "Description": "Description 1"},
        {"Id": 2, "Name": "Name 2", "Description": "Description 1"}
    ];

    var $scope,
        mockService = {
            query: function () {
                return  dummyData;
            }
        };

    beforeEach(inject(function ($rootscope) {
         $scope = $rootscope.$new();
    }));

    it("it can be instantiated", inject(function($controller) {
        var controller = $controller("NormDefinitionsController",
                {
                $scope: $scope,
                myService : mockService
            });

        expect(controller).not.toBeNull();
    }));
});

What am I missing?


Solution

  • Typo (happens to all of us): $rootScope with a capital S.

    Sometimes people forget to inject it. Then you'd get this error:

    ReferenceError: $rootScope is not defined