-
Notifications
You must be signed in to change notification settings - Fork 22
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
Consider removing require-expect from the recommended ruleset #382
Comments
Out of curiosity, what kind of use cases do you see Teams and codebases I have worked in moved to remove most usages of And for me personally, I've always found So I think that covers the reasoning behind the change of the require-expect rule default to
What do you think? |
The two biggest use cases in my current set of projects are:
This is absolutely just personal preference but I actually find the "burden" to be beneficial in that I think it discourages casual remove of test assertions. Maybe it's silly but I've always found the extra step of needing to go and decrement the expected assertion count makes me stop and consider whether I've just made the test worse.
I agree that ultimately each project can configure this rule as they please, which is why I'm not really upset about the change in v8. It just seems like recommending that |
I strongly prefer avoiding a value judgment on As noted, users are welcome to override individual rule settings in their project configs. So no one should be completely blocked by this. But I acknowledge it will be more convenient to remove the rule from the recommended configuration unless a clear consensus emerges here. |
I also like requiring the use of |
I think an option for the rule that could be useful is similar to "except-simple" where assert.expect is required in tests with asserts in blocks etc, but all other assert.expects are errors. I think it makes sense as a default as well, because there are edge cases where you cannot write your test with async/await and this rule has been a good reminder in the past that you're introducing risk by not having assert.expect or assert.async. |
I agree. Howewer, I think this is what code review is for. (Or, potentially, a more advanced lint rule that can recommend use of The practice I generally follow is that test assertions only belong directly in the test function, not nested inside callbacks or otherwise produced in ways that are not directly under the control of the test function. This practice imho results in tests that are most stable, most valuable, and most strict. Enforcing a rule that makes a badly written test slightly less bad, whilst making all other tests more difficult and cumbersome to develop and maintain, is imho not a good rule, and doesn't result in the junior engineer learning about why these tests are fragile. If we can develop a rule that more generally discourages placing assertions (apart from recording steps, which indeed does happen through the assert object today, unless you use your own array with deepEqual at the end), that might be worth persuing, but otherwise I think I lean towards not recommending this rule by default. More generally, I think due to how widespread this practice is, I think rules like
Yeah, I think a lint rule to detect complex cases would be great. I would prefer such rule to recommend adoption of Perhaps something like |
I don't think we should require using I know QUnit is not only used by Ember developers but this technique is even used in official Ember guides for testing components. Is there a simple way to write a similar test without requiring another tool like Sinon? |
I've raised the topic at https://discuss.emberjs.com/t/the-value-and-benefit-of-assert-expect/20145. |
Can't agree more with this. I'm also a huge fan of the use of |
Friendly reminder that this discussion isn't about removing the rule entirely-- just about removing the rule from the This discussion is about whether including the rule in The fact that people are arguing about whether The intention of the |
After discussion, this example has been updated in ember-learn/guides-source#1940.
@jaswilli I don't think that's silly! This kind of "tactical frictional" is built-in to I believe the steps approach has the added benefit of making the "decrement" more understandable in code review. E.g. no need to reason through the count, but you'd very clearly remove a specific string from the step list. With the steps approach we also limit this friction to dealing with these kind of "steps" e.g. from callbacks and other indirect execution. Regular top-level assertions in the test function (possibly with async-await) do not get this friction applied to them. In any case, projects are of course free to enable
@HeroicEric I believe so, yes, with The Step API is significantly more robust and strict than assert.expect(), and also more strict than typical Sinon use. It is of course possible with more code to configure Sinon nearly-equally strict, but this would require complexity and verbosity in your test code, for a relatively small benefit. I imagine it would quickly feel as an outweighed cost to catch a regression that might never come, e.g. checking exact call count, and call arguments, and the order of calls, and then somehow verify that order across multiple different callbacks. The way to reap these benefits at scale, is to make testing it as non-intrusive and effortless as possible, and then do it in all callback-based tests by default, increasing the chances that it pays back. This is all checked automatically by Examples and more info at https://qunitjs.com/api/assert/verifySteps/ |
Hi,
I'd like to propose that
require-expect
be removed from the recommended set of rules. I think it's odd that we'd actually recommend against usingassert.expect
in tests as using it consistently makes test suites more robust and forbidding its use seems like a case of removing a set of guardrails because, "trust me, I know what I'm doing," which is sort of antithetical to the spirit of a linting tool.I think #222 (comment) was perhaps a mischaracterization of
assert-expect
--I don't believe it's no longer needed nor redundant.My actual preference would be to revert back to recommending
except-simple
, however, I realize that's unlikely to happen at this point 😄Originally posted by @jaswilli in #381 (comment)
The text was updated successfully, but these errors were encountered: