New matcher "hashContaining" similar to rspec's hash_including

This commit is contained in:
gvanhove
2011-03-09 18:56:28 -08:00
parent ce886e20e4
commit 992367dcbc
5 changed files with 188 additions and 0 deletions

View File

@@ -196,6 +196,21 @@ jasmine.any = function(clazz) {
return new jasmine.Matchers.Any(clazz);
};
/**
* Returns a matchable subset of a hash/JSON object. For use in expectations when you don't care about all of the
* attributes on the object.
*
* @example
* // don't care about any other attributes than foo.
* expect(mySpy).toHaveBeenCalledWith(jasmine.hashContaining({foo: "bar"});
*
* @param sample {Object} sample
* @returns matchable object for the sample
*/
jasmine.hashContaining = function (sample) {
return new jasmine.Matchers.HashContaining(sample);
};
/**
* Jasmine Spies are test doubles that can act as stubs, spies, fakes or when used in an expecation, mocks.
*