Skip to content
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

Rule proposal: no-nested-describes #83

Open
jfmengels opened this issue Jul 26, 2016 · 2 comments
Open

Rule proposal: no-nested-describes #83

jfmengels opened this issue Jul 26, 2016 · 2 comments

Comments

@jfmengels
Copy link
Collaborator

Some consider having nested describes a bad practice, and prefer splitting tests into several files. See avajs/ava#222 for a discussion for the introduction of nesting in AVA (which is currently not accepted, and probably never will).

I'm proposing this rule for people such as myself that like this train of thought but use Mocha in their projects.

Examples

Invalid

describe('foo', function() {
  describe('bar', function() {
    // ...
  });
});

Valid

describe('foo', function() {
  // ...
});

describe('bar', function() { // or even split it into several files
  // ...
});

Now that I think about it, another way to do this could be to only allow one describe per file, which would make the valid example invalid. This would probably be better as a different but complimentary rule (either allow one describe per file, or one describe per "level").

@lo1tuma
Copy link
Owner

lo1tuma commented Jul 26, 2016

I’m not sure if I fully understood the proposal.

Do you want to have two rules, where one can limit to amount of nested describes and one rule that limits the usage of describes per scope?

@jfmengels
Copy link
Collaborator Author

Sorry for kind of proposing two rules at the same time and making this confusing.

My initial proposal is to have a rule that forbids having a describe inside of another describe.

And when writing this proposal, I noticed that we could take this "no nesting" (or maybe AVA-ification) one step further and forbid having more than one describe in a single file, which I think should probably be a different rule.

I proposed both at the same time as there is some overlapping (if I have nested describes, both rules would trigger). Maybe the second rule should only warn about sibling describes

describe(...);
describe(...);

and not for nested describes

describe(function() {
  describe(...);
});

as that one would be handled by the first rule.

tl;dr: What I'm thinking of now:

  • One rule for forbidding nested describes
  • One rule for forbidding sibling describes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants