Closed gabalafou closed 3 years ago
No, because that does not demonstrate that .throwError
now allows chaining. You need to have .throwError().and
Both additions to the unit test code that I made were to demonstrate that chaining now works after invocations to .throwError
and .ok
Yeah, I got that, but I'm not sure what real use-case it has. It seems to me like you'd verify the function meets other expectations before you invoke it. Not saying this shouldn't be added, it looks like a nice addition.
I added chaining to .throwError
because I had written a test that utilized such chaining for some real world code where I work. However, I don't remember what that test line looked like, nor if it was actually a good use case. :-)
However, I think API self-consistency is sufficient justification for a change like this; I don't think one needs to come up with a good use case for said consistency. It's the opposite—it is the inconsistencies within an API—that need justification through concrete examples.
And in expect.js, every other Assertion method is chainable because every other Assertion method returns this
. If .throwError
and .ok
are going to break from this pattern, then there should be a really good reason for it, and it ought to be documented.
However, I think API self-consistency is sufficient justification for a change like this; I don't think one needs to come up with a good use case for said consistency. It's the opposite—it is the inconsistencies within an API—that need justification through concrete examples.
Ha! Well said :smiley:
@gabalafou I agree that this should be documented. I think it is not about the API self-consistency, but good habit. The lib makes developer do the good way; .ok and .throwException should be terminal flag
Why should .ok, .throw, .empty, and .fail be terminal? Why is that good habit?
LGTM, though would it not make more sense to test the function throwing in the opposite order?
If the object is not a function, it would just fail when attempting to invoke it, no?