Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

prefer-hooks-on-top.md 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Suggest having hooks before any test cases (`prefer-hooks-on-top`)
  2. All hooks should be defined before the start of the tests
  3. ## Rule Details
  4. Examples of **incorrect** code for this rule
  5. ```js
  6. /* eslint jest/prefer-hooks-on-top: "error" */
  7. describe('foo', () => {
  8. beforeEach(() => {
  9. //some hook code
  10. });
  11. test('bar', () => {
  12. some_fn();
  13. });
  14. beforeAll(() => {
  15. //some hook code
  16. });
  17. test('bar', () => {
  18. some_fn();
  19. });
  20. });
  21. // Nested describe scenario
  22. describe('foo', () => {
  23. beforeAll(() => {
  24. //some hook code
  25. });
  26. test('bar', () => {
  27. some_fn();
  28. });
  29. describe('inner_foo', () => {
  30. beforeEach(() => {
  31. //some hook code
  32. });
  33. test('inner bar', () => {
  34. some_fn();
  35. });
  36. test('inner bar', () => {
  37. some_fn();
  38. });
  39. beforeAll(() => {
  40. //some hook code
  41. });
  42. afterAll(() => {
  43. //some hook code
  44. });
  45. test('inner bar', () => {
  46. some_fn();
  47. });
  48. });
  49. });
  50. ```
  51. Examples of **correct** code for this rule
  52. ```js
  53. /* eslint jest/prefer-hooks-on-top: "error" */
  54. describe('foo', () => {
  55. beforeEach(() => {
  56. //some hook code
  57. });
  58. // Not affected by rule
  59. someSetup();
  60. afterEach(() => {
  61. //some hook code
  62. });
  63. test('bar', () => {
  64. some_fn();
  65. });
  66. });
  67. // Nested describe scenario
  68. describe('foo', () => {
  69. beforeEach(() => {
  70. //some hook code
  71. });
  72. test('bar', () => {
  73. some_fn();
  74. });
  75. describe('inner_foo', () => {
  76. beforeEach(() => {
  77. //some hook code
  78. });
  79. test('inner bar', () => {
  80. some_fn();
  81. });
  82. });
  83. });
  84. ```