anything (wildcard) matcher for toHaveBeenCalledWith() ?

1,122 views
Skip to first unread message

Ben Ellis

unread,
Jan 25, 2012, 9:39:05 AM1/25/12
to jasmi...@googlegroups.com
In Rspec, I'd do something like obj.should_receive(:method_name).with("foo",anything) to specify a case where obj.method_name() should be called and the first argument must be "foo" but the second argument can be whatever.

Is there a way to do the equivalent in Jasmine?

expect(obj.method_name).toHaveBeenCalledWith('foo',anything); //doesn't work, but would be nice if it did...

The code in question is a NodeJS app that calls memcache client's get method passing "foo" and an anonymous function. I just want to assert that "foo" is passed as the first argument. Suggestions?

Ben Ellis

unread,
Feb 7, 2012, 11:18:29 AM2/7/12
to jasmi...@googlegroups.com
As mentioned in another post, you can use Jasmine's any() matcher:

expect(obj.method_name).toHaveBeenCalledWith('foo',any(Function)); // This works

Reply all
Reply to author
Forward
0 new messages