Unknown $rootElementProvider: Qunit + angularjs integration [closed]

只愿长相守 提交于 2019-12-06 00:03:52

问题


When I try to inject $location service in unit test (qunit) I get error: Unknown $rootElementProvider <- $rootElement <- $location

Other things without $location service dependency are injected correctly.

 var $injector = angular.injector(['ng', 'myApp']);
 var $location = $injector.get('$location');

source: http://jsfiddle.net/H4qGb/5/

One more strange error happens in the second test.

Does anybody know how to integrate angular with qunit best way?


回答1:


You should be using the angularjs mocks.

http://code.angularjs.org/1.1.5/angular-mocks.js

You can then instruct your injector to also use these mocks.
var $injector = angular.injector(['ngMock','ng', 'myApp']);

http://jsfiddle.net/jxVDT/



来源:https://stackoverflow.com/questions/16273373/unknown-rootelementprovider-qunit-angularjs-integration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!