22

我正在尝试注入$scope茉莉花测试,但得到异常

Unknown provider: $rootscopeProvider <- $rootscope

我的规格文件是这样的:

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();
    }));
});

我错过了什么?

谢谢

戴夫

4

1 回答 1

48

错字(发生在我们所有人身上): $rootScope大写S

有时人们忘记注射它。然后你会得到这个错误:

ReferenceError: $rootScope is not defined
于 2013-03-29T18:07:56.737 回答