quickmock icon indicating copy to clipboard operation
quickmock copied to clipboard

Annotating with $inject property not supported

Open Mojova opened this issue 9 years ago • 3 comments

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.

Mojova avatar May 18 '15 06:05 Mojova

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.

tennisgent avatar May 18 '15 21:05 tennisgent

Just submitted a pull request to fix this issue, @tennisgent. Thanks for this library, btw.

mitchogaard avatar Feb 18 '16 20:02 mitchogaard

@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?

mitchogaard avatar Feb 19 '16 19:02 mitchogaard