quickmock icon indicating copy to clipboard operation
quickmock copied to clipboard

Quick mock in strict mode

Open jolafrite opened this issue 9 years ago • 7 comments

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

jolafrite avatar Mar 14 '15 16:03 jolafrite

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.

tennisgent avatar Mar 18 '15 18:03 tennisgent

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.

jolafrite avatar Mar 20 '15 03:03 jolafrite

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

Mojova avatar May 15 '15 11:05 Mojova

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

slepkaviba avatar May 15 '15 13:05 slepkaviba

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.

tennisgent avatar May 15 '15 13:05 tennisgent

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

slepkaviba avatar May 15 '15 13:05 slepkaviba

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.

tennisgent avatar May 15 '15 13:05 tennisgent