Mock dep to test service error

604 views
Skip to first unread message

Mike Spainhower

unread,
Feb 20, 2013, 6:00:16 AM2/20/13
to ang...@googlegroups.com
Is the documentation at http://docs.angularjs.org/guide/dev_guide.services.testing_services still valid?  I am trying to mock $window in the same fashion for a service's unit test, but get the following error when $provide.value('$window', mock) is present

Error: Argument 'fn' is not a function, got Object
            at assertArg (/home/spainhower/apps/frontend/angular-piwik/vendor/angular.js:975)
            at assertArgFn (/home/spainhower/apps/frontend/angular-piwik/vendor/angular.js:986)
            at annotate (/home/spainhower/apps/frontend/angular-piwik/vendor/angular.js:2306)
            at invoke (/home/spainhower/apps/frontend/angular-piwik/vendor/angular.js:2789)
            at /home/spainhower/apps/frontend/angular-piwik/vendor/angular.js:2662


Thanks!

Christian Dannie Storgaard

unread,
Mar 19, 2013, 1:32:08 PM3/19/13
to ang...@googlegroups.com
I believe the trick is to return null from the module ($provide) function - as it seems you've discovered as well ;)

So, for others stumbling on to this thread, this won't work:
module ($provide) ->
      $provide.value '$window', mock
      $provide.value '$q', q

this will:
module ($provide) ->
      $provide.value '$window', mock
      $provide.value '$q', q
      null

Mike Spainhower

unread,
Mar 19, 2013, 6:14:11 PM3/19/13
to ang...@googlegroups.com
Thank you for posting this for others to find later, I forgot to come back and close this out :-)


--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/gCGF_B4eQkc/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

David Brunner

unread,
Jul 4, 2013, 5:18:11 PM7/4/13
to ang...@googlegroups.com
Thanks for posting this.  It was a frustrating problem.

Angular team, it would be great if you could note this in the documentation, or throw an informative error.  I lost at least an hour on this.

David

Hiswe Halya

unread,
Sep 22, 2013, 11:20:51 AM9/22/13
to ang...@googlegroups.com
You saved my day…

Jared Stark

unread,
Dec 13, 2013, 12:42:30 PM12/13/13
to ang...@googlegroups.com
Saved my day as well. Thanks

Patryk Ziemkowski

unread,
Dec 28, 2013, 8:11:15 PM12/28/13
to ang...@googlegroups.com
Thank you, I'd never think of that! You have saved me a lot of time.
Reply all
Reply to author
Forward
0 new messages