After working with RSpec for a bit, I wanted to be able to use something like the hash_containing method with my expectations in jasmine. So that instead of:
expect(foo).toHaveBeenCalled();
var objectArg = foo.mostRecentCall.args[0];
expect(objectArg.bar).toEqual('baz');
I could just write:
expect(foo).toHaveBeenCalledWith(jasmine.objectContaining({bar: 'baz'}));
As I was writing this I tried to model it on the existing jasmine.Any object. I ended up encountering a couple of places in the code where there were explicit checks like
if (a instanceof jasmine.Matchers.Any) {
return a.matches(b);
}
or
if (value instanceof jasmine.Matchers.Any) {
this.emitScalar(value.toString());
}
It seemed like it would be bad form to tack in a new instanceof check. I ended up changing both equals_ and PrettyPrinter.format to check for the existance of a specific method on the object rather than it's type. I called the methods jasmineMatches and jasmineToString so they could be mixed in only in tests and not conflict with any existing methods already named matches or toString on the objects. I talked through this a bit with Davis today, but I wanted to get out a description of the idea behind the pull request in case there were any other questions.