Easymock and Sinon

127 views
Skip to first unread message

Angelo Chen

unread,
Apr 15, 2013, 10:56:34 AM4/15/13
to Sinon.JS
Hi,

In Java there is Easymock to mock a java interface for testing, what
is the closest we can use in Sinonjs to achieve the similar feature?
thanks,

Angel

Christian Johansen

unread,
Apr 15, 2013, 1:01:36 PM4/15/13
to sin...@googlegroups.com
I don't know Easymock. Sinon is function-oriented, and provides few
tools to work with entire objects. If you want you can stub all methods
of an object like this:

sinon.stub(object);

Christian

Maximilian Antoni

unread,
Apr 15, 2013, 1:25:01 PM4/15/13
to sin...@googlegroups.com
I assume have a JavaScript prototype with a constructor definition. Something like this:

function MyThing() {}
MyThing.prototype.doesStuff = function () { /* ... */ };

In that case, the closest thing to Easymock is:

var myStubbedThing = sinon.createStubInstance(MyThing);

This will not invoke the constructor, but create an object of the same type and stub out all functions on it.

-Max
> --
> You received this message because you are subscribed to the Google Groups "Sinon.JS" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to sinonjs+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages