tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 195 forks source link

add functionality to check if an object is included in another object #54

Closed rafmagana closed 12 years ago

rafmagana commented 12 years ago

Some days ago I was using should.js to test an API, I needed to test against a JSON object which was a response from the API, there was some properties/values in the response I didn't care about, look at this case:

Reponse

  var response = { 'attr1':'value1': 'attr2':'value2'}

Wanted to test if the properties/values of this object were part of the response:

var my_local_obj = { 'attr1':'value1'}

should.include and includeEql to the rescue, right? well, no

  response.should.include(my_local_object); // it only works with strings, elements of an array, etc
  response.should.includeEql(my_local_object); // It only works with arrays

so I made this patch to support just that, hope you find it interesting.

maybe I should have added this feature to the includeEql() method, I just think includeEql() is confusing, I'd like to have the include() and includeEql() functionality in the same method but I'd like to know what you think.

Thanks.

rafmagana commented 12 years ago

any comment?

rafmagana commented 12 years ago

what do you think now?

tj commented 12 years ago

looks a lot better, ill comment inline

rafmagana commented 12 years ago

what do you think now?

tj commented 12 years ago

merged/tweaked as a single commit

tj commented 12 years ago

in general though shorter variable names (that still make sense) == better

rafmagana commented 12 years ago

cool, thanks!