我正在尝试将$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();
}));
});
我错过了什么?
感谢
戴夫
答案 0 :(得分:48)
错字(发生在我们所有人身上):$rootScope
首都为S
。
有时人们会忘记注射它。然后你会收到这个错误:
ReferenceError: $rootScope is not defined