Feature request: add 'properties' assertion
See original GitHub issueThere’s a pretty common case that the existing deep.equal, deep.property, and contains.keys APIs don’t cover, namely asserting that an object should have some properties of some given values. Namely, I’d like to be able to say:
obj = {...};
expect(obj).to.have.properties({
a: 42,
b: "someVal"
});
obj is allowed to have other properties as well, but fails if a or b is absent or has a different value.
Here’s the coffeescript I hacked up to do this locally, which barely works:
chai.Assertion.addMethod 'properties', (expectedPropertiesObj) ->
args = ([key,val] for own key,val of expectedPropertiesObj)
args = _.flatten(args)
this.property.apply(this, args)
Issue Analytics
- State:
- Created 11 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Property Content Assertions | ReadyAPI Documentation
The Message Content assertion checks the content of messages and properties according to complex rules. This assertion is deprecated. Use the Smart Assertion...
Read more >Assertion TestStep | Functional Testing - SoapUI
Use the Add Assertion wizard to easily select and configure assertions to be included in the Assertion TestStep. After selecting the Source, the...
Read more >Add or Remove XML Element(s) Assertion - TechDocs
If you are removing an element, specify the context variable that contains a reference to remove a specific signature or other element(s). This ......
Read more >Can I add annotations to object property assertion from jena?
Jena, though it has some support for OWL via OntModels, is really an RDF-based API. Statements in Jena are just a class representing...
Read more >Automating Response Validation With Assertions In Postman
This is a powerful feature to create really robust & fast integration tests. ... #4) Now, let's try adding a test to this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there plugin that does this? I just realized I have written wrong tests (they were passing although they were not doing anything). Maybe add another base test like “.properties”. I am not experienced with chai but maybe you need feedback from people like me. 😃 I now need to write .property for each of the properties I want to check.
(Update1) It seems that http://chaijs.com/plugins/chai-subset is doing what I want. (Update2) Of course I cannot make it work with chai-things sigh.
to.include
works exactly like you want:– https://www.chaijs.com/api/bdd/#includeval-msg