I have a very simple Mocha test (a copy of code that I have seen dozens of times)
When I run it, angular mocks appears to successfully load the injected resources and all their dependencies and successfully makes it to line 9. When I step into the $rootScope.new() function it goes directly to the catch block.
with e as "undefined is not a function"
I am not understanding what is going on here. The variable blockFns[i] is a function, or at least the Chrome debugger says it is. So I don't understand why the call to injector.invoke fails. Here is the stack trace.
You need to inject $rootScope
before you call $rootScope.$new()
like so:
var $rootScope;
beforeEach(inject(function($injector){
$rootScope = $injector.get('$rootScope');
}));
Updated
Actually the issue was that it should be $rootScope.$new()
instead of $rootScope.new()
.