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

Quick mock in strict mode #4

Open jolafrite opened 9 years ago

jolafrite commented 9 years ago

Hi

I'm currently starting to use your plugins as it will be great shortcut on my testing scripts. I encountered some issues and I think it would be good to talk about it with you.

1- The method mockProvider, when looping on the arguments and call getMockForProvider line 33, I got undefined on all the arguments. I guess it's because I activated the strict mode, so it disable func.arguments. I found a work around by converting the function into a string a get the arguments with a regular expression :

var currProviderDeps = providerData[2][1];
      currProviderString = currProviderDeps.toString(),
      depList = currProviderString.slice(currProviderString.indexOf('(') + 1, currProviderString.indexOf(')')).match(/([^\s,]+)/g);

2- I think It would be good to add to the documentation that, it only works if you annotate all your injectable objects by hand or using ng-annotate or the variable modObj._invokeQueue will always be empty

tennisgent commented 9 years ago

Hi @jolafrite, here are my responses to your points:

1) Thanks for noticing the strict mode. I'll make a couple of changes to make it strict-safe. I don't know how I missed that. I'll get it fixed asap.

2) As for the annotation, it should work just fine whether your provider's dependencies are annotated or not. For example:

.service('myService', function(myDependency1, myDependency2){
    // some code
})

You should be able to test that just fine using quickmock. The reason is because quickmock annotates the provider on the fly in memory before grabbing its dependencies. You can see examples of that in the example test for the UserFormValidator service. That service is not annotated, yet the test for it works just fine.

Hopefully that makes sense. If you have any other questions or if I've missed something else, please let me know.

Thanks.

jolafrite commented 9 years ago

I found later that ng-annotate also have hard time to find injectable elements and can't do its job. To get it working, I need to tag by myself with /@ngInject/ So I guess that is why Quickmock can make it too

ps: I am using webpack.

Mojova commented 9 years ago

It looks like this is fixed in master, but NPM is still serving 1.0.6 that has this bug.

slepkaviba commented 9 years ago

Hi @tennisgent,

I also wanted to ask about strict mode fix. Are there still known issues with that one or its already planned as release?

Br

tennisgent commented 9 years ago

Yes, it's been fixed on master. Unfortunately master isn't quite at a stable point where I can add an additional official release for it. I'm still working on it. It won't be long now. Thanks for your interest though.

slepkaviba commented 9 years ago

Thanks for the good news, if you can use any help - will be glad to provide it. )) (or at least try)

tennisgent commented 9 years ago

I just published 1.0.7 which has a fix for strict mode. Can someone please pull the latest and test it for me? If you're still seeing the issue, please let me know. If not, I'll close this issue out.