Chain .property() assertions on objects
See original GitHub issueHello,
is there a workaround to allow something like this:
chai.expect({ foo: 'bar', bar: 'foo' })
.to.have.property('foo', 'bar')
.and.to.have.property('bar', 'foo')
;
Issue Analytics
- State:
- Created 10 years ago
- Comments:21 (14 by maintainers)
Top Results From Across the Web
Fluent assertions - how to properly chain after a type check
So your example will change to: SomeObject.Should() .BeAssignableTo<OtherObject>() .Which.SomeStringProperty.Should().StartWith("whatever");.
Read more >Expect / Should - Chai Assertion Library
Negates all assertions that follow in the chain. expect(function () {}).to.not.throw(); expect({a: 1}).to.not.have.property('b'); expect([1, ...
Read more >Testing Arrays and Objects with Chai.js | by Titus Stone
When it comes to testing arrays and objects with Chai.js sometimes the selection of flagging properties and assertions becomes confusing.
Read more >BDD - Expect
The include and contain assertions can be used as either property based language chains or as methods to assert the inclusion of an...
Read more >Optional Chaining vs Assertion Operator in TypeScript
getName()”, we first have to check whether data is not null and not ... Non-null assertion operator will not null guard your property...
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
I just remembered that we have
.include
which can test subset bodies:This should be suitable for testing many properties. You can even combine it with
property
for complex nesting:I quite like the idea of
also
… but it needs some more discussion to fill gaps; for example I can see people expecting to traverse deep objects like so:At the risk of sounding cynical - I can see either implementation getting a few issues springing up discussing semantics and trying to alter them to the users use-case.
Also worth pointing out that
.property()
isn’t the only thing that sets the object to a new one;.throw()
and.ownPropertyDescriptor()
do this too - and potentially more will. We’ll need a solution that works for all of these I believe.