tennisgent / quickmock

quickmock is an simple service for automatically injecting mocks into your AngularJS unit tests using Jasmine or Mocha
http://tennisgent.github.io/quickmock
34 stars 14 forks source link

Issue with $http as a dependency inside of a service #12

Closed mitchogaard closed 8 years ago

mitchogaard commented 8 years ago

I've got a Plunkr here that shows an issue with trying to use $httpBackend inside of a test and a service (named Service)that uses $http that I'm trying to quickmock. QuickMock doesn't seem to handle the mocking/providing of $http properly. That is, assuming I'm doing everything properly here: https://plnkr.co/edit/1ZxwT8KoZAVcqOiuJDDB?p=preview

Note that the only test where QuickMock does not provide Service passes.

tennisgent commented 8 years ago

It looks like you weren't injecting $httpBackend properly. Because of the way quickmock works, you can't use the typical global inject() function. You have to use quickmock's inject method, as shown in an updated version of your plunker here and in this snippet below:

service = quickmock({
    providerName: 'Service',
    moduleName: 'services',
    mockModules: ['mocks'],
    inject: function(_$httpBackend_){
         $httpBackend = _$httpBackend_;
    }
});

Hope that helps. If it does, feel free to close out this issue. If not, let me know and I'll revisit the issue.

mitchogaard commented 8 years ago

Holy crap that's very useful information. I don't recall seeing that in the docs anywhere. Can we get an update somewhere that includes why this is or at least an example such as the one you provided? Thank you very much.

tennisgent commented 8 years ago

@mitchogaard Just FYI, I added this info to the README. Sorry that there previously wasn't any documentation for this feature.