Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toHaveBeenCalledWith does no longer work with custom matcher #536

Closed
tbuschto opened this issue Mar 1, 2014 · 5 comments
Closed

toHaveBeenCalledWith does no longer work with custom matcher #536

tbuschto opened this issue Mar 1, 2014 · 5 comments

Comments

@tbuschto
Copy link

tbuschto commented Mar 1, 2014

In Jasmine 1.3 you could use your custom matcher with toHaveBeenCalledWith, which was especially useful to ensure that the actual argument was identical to the expected one, not just equal. E.g.:

  var mySpy = jasmine.createSpy();
  var foo = {};
  var bar = {};
  mySpy( foo );

  expect( mySpy ).toHaveBeenCalledWith( foo );
  expect( mySpy ).toHaveBeenCalledWith( bar );
  expect( mySpy ).toHaveBeenCalledWith( same( foo ) );
  expect( mySpy ).not.toHaveBeenCalledWith( same( bar ) );

This is no longer possible with Jasmine 2.0, only 'any' and 'objectContaining' are accepted.

@infews
Copy link
Contributor

infews commented Mar 3, 2014

This is intended behavior. Things were muddied and poorly documented in 1.x in this area. We're now making it much more explicit and easier to maintain.

It looks like there are two parts to your question.

First, toHaveBeenCalledWith() uses the equality functionality across parameters. So if you want to have custom equality, you need to add a custom equality tester. This is how any and objectContaining work in 2.0.

However, what you appear to be wanting to do is check that the specific reference is used. This sounds like you want to write a custom matcher that would be named something like toHaveBeenReallyCalledWith() (or some better name) in order to accomplish what you want to do here.

Does this help? If so, I'd like to close this issue.

@tbuschto
Copy link
Author

tbuschto commented Mar 4, 2014

Thank you for the timely response. I did not know about custom equality testers. I think with those I can re-create the pattern I need. Also, in the example the tester is added in "beforeEach". Would it suffice to add it only once at startup?

@tbuschto
Copy link
Author

It seems like custom equality testers do not work with tohaveBeenCalled with, which once again would prevent me for using it to test for identity?

@thcgit
Copy link

thcgit commented Mar 17, 2014

I'm also having the same issue. I have added a custom equality tester but it's not being picked up by toHaveBeenCalledWith.

@sheelc sheelc closed this as completed in 00c8e37 Mar 27, 2014
@sheelc
Copy link
Contributor

sheelc commented Mar 27, 2014

Just pushed a fix where custom equality testers weren't working with toHaveBeenCalledWith. Hopefully that works on master now, but please feel to reopen if it doesn't.

abirembaut added a commit to bonitasoft/bonita-ui-designer that referenced this issue Oct 22, 2015
abirembaut added a commit to bonitasoft/bonita-ui-designer that referenced this issue Dec 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants