spy's andReturn triggers but fails expect(...).toHaveBeenCalled

146 views
Skip to first unread message

Greg Bacon

unread,
Jun 19, 2012, 5:37:14 PM6/19/12
to jasmi...@googlegroups.com
[Also asked on Stack Overflow, where almost 30% of the Jasmine questions are unanswered.]

I’m trying to debug a spy on 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

Davis W. Frank

unread,
Jun 20, 2012, 12:55:57 AM6/20/12
to jasmi...@googlegroups.com
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

--
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.



--
thx,
--dwf

Reply all
Reply to author
Forward
0 new messages