spyObj reset

1,501 views
Skip to first unread message

efleming969

unread,
Aug 24, 2010, 11:53:43 AM8/24/10
to Jasmine
Are there plans to add a reset function for a spyObj?

Davis Frank

unread,
Aug 24, 2010, 4:51:00 PM8/24/10
to jasmi...@googlegroups.com
Interesting idea.  We don't have plans, but if you'd like to contribute a patch with specs, we'll take a look.

--dwf

On Tue, Aug 24, 2010 at 8:53 AM, efleming969 <eflem...@gmail.com> wrote:
Are there plans to add a reset function for a spyObj?

--
You received this message because you are subscribed to the Google Groups "Jasmine" group.
To post to this group, send email to jasmi...@googlegroups.com.
To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.


fschwiet

unread,
Aug 24, 2010, 10:30:25 PM8/24/10
to Jasmine
I found this, sounds like what you wanted.

/**
* Resets all of a spy's the tracking variables so that it can be
used again.
*
* @example
* spyOn(foo, 'bar');
*
* foo.bar();
*
* expect(foo.bar.callCount).toEqual(1);
*
* foo.bar.reset();
*
* expect(foo.bar.callCount).toEqual(0);
*/
jasmine.Spy.prototype.reset = function() {
this.wasCalled = false;
this.callCount = 0;
this.argsForCall = [];
this.calls = [];
this.mostRecentCall = {};
};

:)


On Aug 24, 1:51 pm, Davis Frank <dwfr...@pivotallabs.com> wrote:
> Interesting idea.  We don't have plans, but if you'd like to contribute a
> patch with specs, we'll take a look.
>
> --dwf
>
> On Tue, Aug 24, 2010 at 8:53 AM, efleming969 <efleming...@gmail.com> wrote:
> > Are there plans to add a reset function for a spyObj?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Jasmine" group.
> > To post to this group, send email to jasmi...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > jasmine-js+...@googlegroups.com<jasmine-js%2Bunsu...@googlegroups.com>
> > .

Davis Frank

unread,
Aug 24, 2010, 11:12:36 PM8/24/10
to jasmi...@googlegroups.com
That resets one spy, but not an object of spies.

--dwf

To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.

Erick Fleming

unread,
Aug 24, 2010, 11:30:06 PM8/24/10
to jasmi...@googlegroups.com
http://github.com/efleming969/jasmine/commits/spyobjwrapper

This is what I put together.  It's a little invasive.  But it works for me.

To unsubscribe from this group, send email to jasmine-js+...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/jasmine-js?hl=en.




--
Erick Fleming
Reply all
Reply to author
Forward
0 new messages