Implement a matcher API for "loosely" asserting on deep properties
See original GitHub issueWe have come across this discussion a few times, but for many people deep.equal
is too-strict of an assertion. For example:
- #97 discusses Sinon matchers, and having something similar.
- #324 went a bit further, including showing how Jasmine handles this with
jasmine.any
. - This may help with issues like #193
- This would help to solve issues like #643 (and perhaps tangentially, #426)
- Personally I’ve run into small problems with this stuff before, with things like asserting arguments with chai-spies
The proposal is thus:
Using deep.equal
or similar complex assertions, we are able to make much looser assertions about specific parts of the assertion, using an assertion sentinel in place of a value:
expect(o).to.deep.equal({
foo: 'bar',
baz: chai.match.a('function').with.length(2),
});
expect(someSpy).to.be.calledWith('foo', chai.match.a('string').that.matches(/bar/));
Issue Analytics
- State:
- Created 8 years ago
- Reactions:41
- Comments:20 (9 by maintainers)
Top Results From Across the Web
Matchers - Sinon.JS
Matchers can be passed as arguments to spy.calledOn, spy.calledWith, spy.returned and thecorresponding sinon.assert functions as well as spy.withArgs.
Read more >assert-match - npm
assert -match allows you to check actual value (or its property) not against a specific expected value as standard deep assertions do, but...
Read more >Loose match one value in jest.toHaveBeenCalledWith
I have an analytics tracker that will only call after 1 second and with an object where the intervalInMilliseconds (duration) value is not ......
Read more >Writing Good Assertions - Manning Publications
From Testing JavaScript Applications by Lucas da Costa. In this article, I will teach you techniques to help you write better assertions.
Read more >Karate API Automation-Assertions using matcher APIs - Medium
Assert whole actual JSON against expected JSON using match equals ... create a file named as “EResult.json” under “Karate.api.data” package ...
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
We’ve not added it yet. It’s on my agenda after better error messaging though. Can’t promise timelines but it will be coming!
I ended up implementing @vaskevich approach as a plugin. It even replaces this potentially confusing text about stubs being called. Here it is: