How can I mock dependencies for unit testing in RequireJS?

258 views
Skip to first unread message

Evan Larsen

unread,
Jul 26, 2012, 3:38:10 PM7/26/12
to amd-im...@googlegroups.com
I have an AMD module I want to test, but I want to mock out its dependencies instead of loading the actual dependencies. I am using requirejs, and the code for my module looks something like this: 

define(['hurp', 'durp'], function(Hurp, Durp) {
 
return {
    foo
: function () {
      console
.log(Hurp.beans)
   
},
    bar
: function () {
      console
.log(Durp.beans)
   
}
 
}
}

How can I mock out hurp and durp so I can effectively unit test?

James Burke

unread,
Jul 26, 2012, 4:33:43 PM7/26/12
to amd-im...@googlegroups.com
This list is more for implementers of AMD loaders, you will likely get
better answers for these kinds of questions by posting here:

https://groups.google.com/forum/?hl=en_US&fromgroups#!forum/requirejs

That said, you can use the paths config in requirejs to map 'hurp' and
'durp' to mock modules.

If you need more info, best to try in the requirejs list since it is
requirejs-specific.

James
Reply all
Reply to author
Forward
0 new messages