Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
spy's andReturn triggers but fails expect(...).toHaveBeenCalled
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Greg Bacon  
View profile  
 More options Jun 19 2012, 5:37 pm
From: Greg Bacon <greg.ba...@gmail.com>
Date: Tue, 19 Jun 2012 16:37:14 -0500
Local: Tues, Jun 19 2012 5:37 pm
Subject: spy's andReturn triggers but fails expect(...).toHaveBeenCalled

[Also asked on Stack Overflow <http://stackoverflow.com/q/11109397/123109>,
where almost 30% of the Jasmine questions are unanswered.]

I’m trying to debug a spy on
jQuery.post<http://api.jquery.com/jQuery.post/>that isn’t firing, so
as a sanity check, I tried
spyOn(this.viewModel.requests, 'submitRequest').andReturn('fooz');

var ret = this.viewModel.requests.submitRequest();
expect(ret).toEqual('foo');

expect(this.viewModel.requests.submitRequest).toHaveBeenCalled();

This fails with

Expected 'fooz' to equal 'foo'.

But when I change 'fooz' to 'foo' in the argument to andReturn, the test
fails with

Expected spy on submitRequest to have been called.

The spy is returning the canned value, so why does toHaveBeenCalled fail?
Thanks,
Greg


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Davis W. Frank  
View profile  
 More options Jun 20 2012, 12:55 am
From: "Davis W. Frank" <dwfr...@pivotallabs.com>
Date: Tue, 19 Jun 2012 21:55:57 -0700
Local: Wed, Jun 20 2012 12:55 am
Subject: Re: [jasmine-js] spy's andReturn triggers but fails expect(...).toHaveBeenCalled

Have you looked at the jasmine-ajax project?
http://github.com/pivotal/jasmine-ajax

This stops AJAX calls at the XHR level, which gives you a much better
mock/fake to deal with under test. Might be easier to find your problem.

--dwf

--
thx,
--dwf

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »