-
-
Notifications
You must be signed in to change notification settings - Fork 693
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
.deep and .not are permanent? #785
Comments
Hey @andyearnshaw thanks for the issue. Indeed, at current the flags are passed along the chain - which is precisely why we don't have |
@keithamus do you have any links to previous discussions so I can get some context? I looked before I posted but found nothing. |
Hello guys, thanks for your issue @andyearnshaw! At that time I didn't think about assigning a behavior to it, but it does make sense to make it cancel any previous Another possible solution for this is "consuming" the I can't (right away) think of any edge cases I think it would be a great addition, what do you guys think? |
I think the problem with something as innocuous as Part of the problem is we hit a wall with the flexibility of the English language. A more concrete edge case is already demonstrated in #621: expect(fn).to.change(obj, 'key').but.not.by(2) If If we can work around issues like these, then I think we could look into this further, but my opinion right now is "this is not workable in our current setup" because of the above. |
Thanks, guys. I wasn't aware
There don't seem to be any sensible language chains (that I can see) where cancelling the
It might make sense that explicitly specifying |
This again, to me, is a slippery slope. Having a flag cancel out some flags but not others seems like something that would be difficult to articulate properly in the docs, without an influx of issues coming about edge cases. If we are going to add such a feature, I think it has to be something that can be explained in one sentence, like "this flag clears out all previously set flags". |
I can't say that I agree, I think it's easy to reason that One possible safe alternative would be to introduce single flag-eliminating
On Tue, 6 Sep 2016, 16:58 Keith Cirkel, notifications@github.com wrote:
|
Thanks for sharing your opinions, we're having a nice discussion here 😄 After trying to write some examples I ended up agreeing with @keithamus. It makes no sense to say that you Even when doing assertions like I think that having I think |
In general, I strongly promote a one-assertion-per-block style of testing. Conceptually, if I wanted to test if something was green and tasty, then my code would be structured as follows: describe("something", () => {
let something;
before(() => {
something = someFn();
});
it("is green", () => {
expect(something).to.be.green;
});
it("is tasty", () => {
expect(something).to.be.tasty;
});
}); I prefer this style of testing over more concise alternatives that perform both assertions inside the same With all of that said, there are occasions when we need to perform two or more assertions in order to test a single concept. More importantly, there are occasions when there's no point in running the second assertion when the first assertion fails. @andyearnshaw's original example is such an occasion: expect(setPrivs(target, props)).not.to.equal(props).and.to.deep.equal(props); It's appropriate to include both of these assertions inside a single block. And it's more convenient to be able to do so by combining the assertions in a single line using language chains. But is the convenience worth a breaking change to I think I'd be more accepting of a non-breaking change, such as adding a new language chain like |
I'll concede that
It would be nice if In any case, thanks for the comments, I really enjoyed the discussion 😄. |
Thank you too for bringing this proposal @andyearnshaw! For now I'll close this since we all agreed on this matter. |
I wrote the following test for a function that I expect to assign an object's properties to another object (in a similar vein to
Object.assign
):This fails, even if I switch the order (deep before not). If I separate out the expressions, however, it passes:
Looking at the documentation, I can understand why it fails. Both
deep
andnot
apply to any chains following and there appears to be no way to unset them that I can see. Looking at the natural language of my expression, it makes sense that theand
chain should unset them.I realise that this would be a breaking change, so perhaps an alternative would be to introduce
but
:This behaviour would be very natural as "but" is "used to introduce a phrase or clause contrasting with what has already been mentioned."
Hopefully this makes sense and I haven't overlooked something.
The text was updated successfully, but these errors were encountered: