Stubbing global function

4 views
Skip to first unread message

Roy Kolak

unread,
May 18, 2010, 12:54:33 PM5/18/10
to jspec
I'm trying to stub a global function (yeah... third party crap).
Here's my approach

it 'should call multiTrack'
stub(window, 'dcsMultiTrack')

// Direct call, just for testing...
dcsMultiTrack()

expect(window).to(receive, 'dcsMultiTrack');
end

This is the result:
"expected [object DOMWindow].dcsMultiTrack() to be called once, but
was not called"

Can't seem to track why this error is the outcome. Anyone encounter
this behavior before?

--
JSpec thanks you for your interest and support! To post simply reply
to this email.

documentation: http://jspec.info
unsubscribe: jspec+un...@googlegroups.com
group: http://groups.google.com/group/jspec

Kevin Gisi

unread,
May 18, 2010, 12:58:42 PM5/18/10
to js...@googlegroups.com
Have you tried document rather than window?
--
Sent from my mobile device

-Kevin W. Gisi
ke...@kevingisi.com | (916) 538-4474
http://www.kevingisi.com

Roy Kolak

unread,
May 18, 2010, 1:59:56 PM5/18/10
to js...@googlegroups.com
Yes I have. The failure is the same.

Roy Kolak

unread,
May 19, 2010, 12:12:38 PM5/19/10
to jspec
I was missing something.

I was calling the method before setting up the should.receive. At
first it
seemed like I would call the method first then assert that it was
called,
but then I realized the problem in that… how would jspec know which
method
to record the calls on if I didn't tell it before the method was
called.

Thanks guys


On May 18, 12:59 pm, Roy Kolak <roy.ko...@gmail.com> wrote:
> Yes I have. The failure is the same.
>
>
>
>
>
> On Tue, May 18, 2010 at 11:58 AM, Kevin Gisi <ke...@kevingisi.com> wrote:
> > Have you tried document rather than window?
>
> > On 5/18/10, Roy Kolak <roy.ko...@gmail.com> wrote:
> > > I'm trying to stub a global function (yeah... third party crap).
> > > Here's my approach
>
> > > it 'should call multiTrack'
> > >    stub(window, 'dcsMultiTrack')
>
> > >    // Direct call, just for testing...
> > >    dcsMultiTrack()
>
> > >    expect(window).to(receive, 'dcsMultiTrack');
> > > end
>
> > > This is the result:
> > > "expected [object DOMWindow].dcsMultiTrack() to be called once, but
> > > was not called"
>
> > > Can't seem to track why this error is the outcome. Anyone encounter
> > > this behavior before?
>
> > > --
> > > JSpec thanks you for your interest and support! To post simply reply
> > > to this email.
>
> > > documentation:http://jspec.info
> > > unsubscribe: jspec+un...@googlegroups.com<jspec%2Bunsu...@googlegroups.com>
> > > group:http://groups.google.com/group/jspec
>
> > --
> > Sent from my mobile device
>
> > -Kevin W. Gisi
> > ke...@kevingisi.com | (916) 538-4474
> >http://www.kevingisi.com
>
> > --
> > JSpec thanks you for your interest and support! To post simply reply
> > to this email.
>
> > documentation:http://jspec.info
> > unsubscribe: jspec+un...@googlegroups.com<jspec%2Bunsu...@googlegroups.com>
> > group:http://groups.google.com/group/jspec
>
> --
> JSpec thanks you for your interest and support! To post simply reply
> to this email.
>
> documentation:http://jspec.info
> unsubscribe: jspec+un...@googlegroups.com
> group:http://groups.google.com/group/jspec

Reply all
Reply to author
Forward
0 new messages