简体   繁体   中英

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?

THanks

Dave

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM