Message from discussion
Odd result for spying on Mojo.Controller.SceneControlle r.listen/stopListening
Received: by 10.220.176.73 with SMTP id bd9mr2709255vcb.7.1290480267234;
Mon, 22 Nov 2010 18:44:27 -0800 (PST)
X-BeenThere: jasmine-webos@googlegroups.com
Received: by 10.220.158.5 with SMTP id d5ls886659vcx.2.p; Mon, 22 Nov 2010
18:44:26 -0800 (PST)
MIME-Version: 1.0
Received: by 10.220.194.2 with SMTP id dw2mr331491vcb.25.1290480266379; Mon,
22 Nov 2010 18:44:26 -0800 (PST)
Received: by q18g2000vbm.googlegroups.com with HTTP; Mon, 22 Nov 2010 18:44:26
-0800 (PST)
Date: Mon, 22 Nov 2010 18:44:26 -0800 (PST)
In-Reply-To: <b341d37c-4a69-447a-ac05-99c954c2bea4@a37g2000yqi.googlegroups.com>
X-IP: 98.207.4.18
References: <b341d37c-4a69-447a-ac05-99c954c2bea4@a37g2000yqi.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; en-US)
AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.587.0 Safari/534.12,gzip(gfe)
Message-ID: <11585e18-5e7c-4b81-aad1-022548fa29cc@q18g2000vbm.googlegroups.com>
Subject: Re: Odd result for spying on Mojo.Controller.SceneController.listen/stopListening
From: DWF <dwfr...@pivotallabs.com>
To: jasmine-webos <jasmine-webos@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
The problem you're running into is that #bind and #bindAsEventListener
return different instances of anonymous functions with every call. So
you're comparing two different functions (even though they are
'equivalent').
Two suggestions:
1) Don't care which function is called and match jasmine.any(Function)
for the 3rd parameter
2) Bind the function on the assistant constructor or #setup and save
it off, then compare against that property
--dwf
On Nov 22, 3:53=A0pm, Naleag Deco <gdco...@gmail.com> wrote:
> I'm seeing some weird behaviour when trying to spy on listen/
> stopListening calls.
>
> My spec looks something like ... (I apologize for spelling mistakes)
>
> var assistant;
>
> beforeEach(function () {
> =A0 =A0 =A0 =A0 =A0assistant =3D
> jasmine.webos.createStubSceneAssistant('TestView', arg);
>
> });
>
> it('should pass this test', function() {
> =A0 =A0 =A0 =A0 spyOn(assistant.controller, 'listen');
> =A0 =A0 =A0 =A0 spyOn(assistant.controller, 'stopListening');
>
> =A0 =A0 =A0 =A0 assistant.setup();
>
> expect(assistant.controller.listen).toHaveBeenCalledWith("an_element_id",
> Mojo.Event.listTap,
> assistant.a_function.bindAsEventListener(assistant));
> =A0 =A0 =A0 =A0 ...
>
> });
>
> My scene's setup function contains a call to
> "this.controller.listen("an_element_id", Mojo.Event.listTap,
> this.a_function.bindAsEventListener(this));" and there is a similar
> call in my cleanup code.
>
> The code appears to work, but Jasmine reports an error similar to:
> "Expected spy to have been called with ['an_element_id', 'mojo-list-
> tap', Function ] but was called with [['story_list, 'mojo-list-tap',
> Function ]]"
>
> I am unable to figure out why the "real" function call in Jasmine
> winds up being wrapped in another array, and whether that's what
> happens in production code or just via the framework. I have tried
> playing with Mojo.Event.listen/stopListening and with using bind
> instead of bindAsEventListener.
>