Unknown $rootElementProvider: Qunit + angularjs integration [closed]
Asked Answered
C

1

7

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?

Chunk answered 29/4, 2013 at 7:31 Comment(4)
I have this same problem using jasmineLover
Artem, have you found the answer to this problem?Dudeen
No, I switched to jasmine. And now I realize that jasmine has much better integration with angular.Chunk
Your jsfiddle example doesnt work anymoreScheider
H
9

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/

Helvetia answered 30/6, 2013 at 2:17 Comment(2)
Your JS Fiddle doesn't work, and the link just to the JS file isn't helpful in showing how to use it. Can you include an example usage for Jasmine in the answer itself?Intrusion
When I load ngMock, I can't use $http anymore, it's mocked.Rema

© 2022 - 2024 — McMap. All rights reserved.