quickmock
quickmock copied to clipboard
Annotating with $inject property not supported
You can annotate dependencies in angular with the $inject property:
angular
.module('foo')
.factory('FooFactory', FooFactory);
FooFactory.$inject = ['dep1', 'dep2', 'dep3'];
function FooFactory(dep1, dep2, dep3) {
//code
}
This isn't compatible with 1.0.7 of quickmock. Running the library through a debugger reveals that the problem is at line 35:
for(var i=0; i<currProviderDeps.length - 1; i++){
var depName = currProviderDeps[i];
mocks[depName] = getMockForProvider(depName, currProviderDeps, i);
}
depName is undefined for all i.
Changing the loop in question into
for(var i=0; i<currProviderDeps.$inject.length; i++){
var depName = currProviderDeps.$inject[i];
mocks[depName] = getMockForProvider(depName, currProviderDeps, i);
}
works for the first iteration. For subsequent tests in the suite, it seems to revert to "normal" behavior, i.e. no $inject.
You're right. I need to fix support for $inject
. I had it in there once but apparently broke it in an update somewhere along the line. Sorry. I'll get it fixed.
Just submitted a pull request to fix this issue, @tennisgent. Thanks for this library, btw.
@Aakkosti Looks like @tennisgent merged my pull request in. Do you want to grab the latest (I believe it's untagged right now), verify that it's fixed, and close this?