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.

valid-title.md 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. # Enforce valid titles (`valid-title`)
  2. Checks that the title of Jest blocks are valid by ensuring that titles are:
  3. - not empty,
  4. - is a string,
  5. - not prefixed with their block name,
  6. - have no leading or trailing spaces
  7. ## Rule Details
  8. **emptyTitle**
  9. An empty title is not informative, and serves little purpose.
  10. Examples of **incorrect** code for this rule:
  11. ```js
  12. describe('', () => {});
  13. describe('foo', () => {
  14. it('', () => {});
  15. });
  16. it('', () => {});
  17. test('', () => {});
  18. xdescribe('', () => {});
  19. xit('', () => {});
  20. xtest('', () => {});
  21. ```
  22. Examples of **correct** code for this rule:
  23. ```js
  24. describe('foo', () => {});
  25. describe('foo', () => {
  26. it('bar', () => {});
  27. });
  28. test('foo', () => {});
  29. it('foo', () => {});
  30. xdescribe('foo', () => {});
  31. xit('foo', () => {});
  32. xtest('foo', () => {});
  33. ```
  34. **titleMustBeString**
  35. Titles for test blocks should always be a string.
  36. This is also applied to `describe` blocks by default, but can be turned off via
  37. the `ignoreTypeOfDescribeName` option:
  38. Examples of **incorrect** code for this rule:
  39. ```js
  40. it(123, () => {});
  41. describe(String(/.+/), () => {});
  42. describe(myFunction, () => {});
  43. xdescribe(myFunction, () => {});
  44. describe(6, function () {});
  45. ```
  46. Examples of **correct** code for this rule:
  47. ```js
  48. it('is a string', () => {});
  49. test('is a string', () => {});
  50. xtest('is a string', () => {});
  51. describe('is a string', () => {});
  52. describe.skip('is a string', () => {});
  53. fdescribe('is a string', () => {});
  54. ```
  55. Examples of **correct** code when `ignoreTypeOfDescribeName` is `true`:
  56. ```js
  57. it('is a string', () => {});
  58. test('is a string', () => {});
  59. xtest('is a string', () => {});
  60. describe('is a string', () => {});
  61. describe.skip('is a string', () => {});
  62. fdescribe('is a string', () => {});
  63. describe(String(/.+/), () => {});
  64. describe(myFunction, () => {});
  65. xdescribe(myFunction, () => {});
  66. describe(6, function () {});
  67. ```
  68. **duplicatePrefix**
  69. A `describe` / `test` block should not start with `duplicatePrefix`
  70. Examples of **incorrect** code for this rule
  71. ```js
  72. test('test foo', () => {});
  73. it('it foo', () => {});
  74. describe('foo', () => {
  75. test('test bar', () => {});
  76. });
  77. describe('describe foo', () => {
  78. test('bar', () => {});
  79. });
  80. ```
  81. Examples of **correct** code for this rule
  82. ```js
  83. test('foo', () => {});
  84. it('foo', () => {});
  85. describe('foo', () => {
  86. test('bar', () => {});
  87. });
  88. ```
  89. **accidentalSpace**
  90. A `describe` / `test` block should not contain accidentalSpace
  91. Examples of **incorrect** code for this rule
  92. ```js
  93. test(' foo', () => {});
  94. it(' foo', () => {});
  95. describe('foo', () => {
  96. test(' bar', () => {});
  97. });
  98. describe(' foo', () => {
  99. test('bar', () => {});
  100. });
  101. describe('foo ', () => {
  102. test('bar', () => {});
  103. });
  104. ```
  105. Examples of **correct** code for this rule
  106. ```js
  107. test('foo', () => {});
  108. it('foo', () => {});
  109. describe('foo', () => {
  110. test('bar', () => {});
  111. });
  112. ```
  113. ## Options
  114. ```ts
  115. interface Options {
  116. ignoreTypeOfDescribeName?: boolean;
  117. disallowedWords?: string[];
  118. mustNotMatch?: Partial<Record<'describe' | 'test' | 'it', string>> | string;
  119. mustMatch?: Partial<Record<'describe' | 'test' | 'it', string>> | string;
  120. }
  121. ```
  122. #### `ignoreTypeOfDescribeName`
  123. Default: `false`
  124. When enabled, the type of the first argument to `describe` blocks won't be
  125. checked.
  126. #### `disallowedWords`
  127. Default: `[]`
  128. A string array of words that are not allowed to be used in test titles. Matching
  129. is not case-sensitive, and looks for complete words:
  130. Examples of **incorrect** code when using `disallowedWords`:
  131. ```js
  132. // with disallowedWords: ['correct', 'all', 'every', 'properly']
  133. describe('the correct way to do things', () => {});
  134. it('has ALL the things', () => {});
  135. xdescribe('every single one of them', () => {});
  136. test(`that the value is set properly`, () => {});
  137. ```
  138. Examples of **correct** code when using `disallowedWords`:
  139. ```js
  140. // with disallowedWords: ['correct', 'all', 'every', 'properly']
  141. it('correctly sets the value', () => {});
  142. test('that everything is as it should be', () => {});
  143. describe('the proper way to handle things', () => {});
  144. ```
  145. #### `mustMatch` & `mustNotMatch`
  146. Defaults: `{}`
  147. Allows enforcing that titles must match or must not match a given Regular
  148. Expression. An object can be provided to apply different Regular Expressions to
  149. specific Jest test function groups (`describe`, `test`, and `it`).
  150. Examples of **incorrect** code when using `mustMatch`:
  151. ```js
  152. // with mustMatch: '^that'
  153. describe('the correct way to do things', () => {});
  154. fit('this there!', () => {});
  155. // with mustMatch: { test: '^that' }
  156. describe('the tests that will be run', () => {});
  157. test('the stuff works', () => {});
  158. xtest('errors that are thrown have messages', () => {});
  159. ```
  160. Examples of **correct** code when using `mustMatch`:
  161. ```js
  162. // with mustMatch: '^that'
  163. describe('that thing that needs to be done', () => {});
  164. fit('that this there!', () => {});
  165. // with mustMatch: { test: '^that' }
  166. describe('the tests that will be run', () => {});
  167. test('that the stuff works', () => {});
  168. xtest('that errors that thrown have messages', () => {});
  169. ```