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

New rule suggestion: Place all hooks at the top of the block. #356

Closed
garyking opened this issue Jul 30, 2019 · 2 comments · Fixed by #425
Closed

New rule suggestion: Place all hooks at the top of the block. #356

garyking opened this issue Jul 30, 2019 · 2 comments · Fixed by #425

Comments

@garyking
Copy link
Contributor

I would like to suggest a new rule, to place all hook blocks before any other blocks.

So, this is good:

describe('module', () => {
  let a
  
  beforeEach(() => {
    a = new A();
  })
  
  test('function', () => {
    expect(a).not.toBeUndefined();
  })
})

And this is bad:

describe('module', () => {
  let a
  
  test('function', () => {
    expect(a).not.toBeUndefined();
  })
  
  beforeEach(() => {
    a = new A();
  })
})
@G-Rath
Copy link
Collaborator

G-Rath commented Jul 30, 2019

Sounds like it could be useful - I'd think a good target goal would be something like "all hooks must be above the first test case in a block".

PRs welcome 😄

@SimenB
Copy link
Member

SimenB commented Oct 12, 2019

🎉 This issue has been resolved in version 22.18.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants