-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: Matchers #7
Comments
Regarding multiple ways of doing the same thing. I consider this an antipattern leading to unnecessary headaches. It forces the programmer to make more decisions that he actually needs. It also requires him to visit the documentation to see if maybe there is something actually different between the options. It also makes the library author have to pick a version for each example, leading to additional overhead and making documentation less straightforward. Regarding essential matchers. I am a big fan of appropriate and concise naming. Therefore I would prefer overloading some matchers to make it easier to reason.
Knowing this it is easier to resolve the assymetric ones. Just make it consistent with symmetric.
|
@sz-piotr thanks for your input!
Yeah, I see your point. Agreed, lets start without these additional matchers. I like having Another thing that I wanted to discuss is what about matchers for promises? These days I don't use |
Yeah, I also think that you only need matchers for promise rejections. Not sure about |
@sz-piotr I wanted to drop |
@krzkaczor do here is how I see it. There are two operators in JS. What we want to do is combine those two operators under the name of If we go your route which is quite nice in its simplicity we run into the following problems.
Despite those problems the more I think about it the more I am convinced it is the way to go. Also if it does not use typeof or instanceof directly it is ok to use stuff like |
yeah i think the right way is to enforce it on type level and call it a day... (no need even for runtime exception then)
That's quite a rare situation and if your run up-to-date version of earl you should be fine 🤔
I never thought it's simple :D simple would be only having 1 way of doing things which works always properly (which we try to have here) 😆
I am glad you like it! And yes Arrays also can be supported this way which is kinda neat... I am working on it here: #10 |
I had this crazy realization yesterday: what if we push using asymmetric matchers to the limit basically turning this library in a pattern matching assertion library 🤔 Then we could drop For example: // this almost already works already
match(x, {
name: a(String),
age: numberCloseTo(20, { delta: 2 }),
})
// match strict mock to fully verified mock
match(mock, aVerifiedMock())
// assert mocks basically by creating a pattern out of fresh mock
match(looseMock, mock().calledOnceWith(1, 2, 3).calledTwiceWith(1))
// for waffle
match(tx, aRevertedTx('revert reason')) Am I crazy that I kinda like it? Also, it allows leveraging typescript assertion functions. It also solves discussions about "should this be a regular matcher or asymmetric matcher". Finally, it doesn't require changing the API of EDIT: |
I think "meh", this actually looks less intuitive than separate named checks for different occasions |
I am closing this one as initial implementation and API direction is done. Thanks everyone for your involvment! |
This issue facilitates discussions about matchers design
Problem of having multiple ways to match the same thing
toEqual
is quite a beast and thus many matchers can be implemented just by using it:I had this problem on my mind for some time already and I initially thought that avoiding this duplication entirely is a good thing but I believe that having some level of consistency with
chai
can beneficial. For example, I think1)
is fine (it's clear and shorter 🤔)Any thoughts on this one?
Essentials matchers to implement in the first batch
toBeTruthy
toBeFalsy
toThrow
(match message and match error type as separate matches? to read: Using expect(...).to.throw(...) with custom assertion function chaijs/chai#655)Asymmetric:
any
(oranyInstanceOf
? much longer, much more explicit... i need to admit thatany
was confusing for me when I first saw it)anyString
/anyStringMatching
/anyStringContaining
anyNumber
The text was updated successfully, but these errors were encountered: