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-expect.md 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # Enforce valid `expect()` usage (`valid-expect`)
  2. Ensure `expect()` is called with a single argument and there is an actual
  3. expectation made.
  4. ## Rule details
  5. This rule triggers a warning if `expect()` is called with more than one argument
  6. or without arguments. It would also issue a warning if there is nothing called
  7. on `expect()`, e.g.:
  8. ```js
  9. expect();
  10. expect('something');
  11. ```
  12. or when a matcher function was not called, e.g.:
  13. ```js
  14. expect(true).toBeDefined;
  15. ```
  16. or when an async assertion was not `await`ed or returned, e.g.:
  17. ```js
  18. expect(Promise.resolve('Hi!')).resolves.toBe('Hi!');
  19. ```
  20. This rule is enabled by default.
  21. ## Options
  22. ```json5
  23. {
  24. type: 'object',
  25. properties: {
  26. alwaysAwait: {
  27. type: 'boolean',
  28. default: false,
  29. },
  30. minArgs: {
  31. type: 'number',
  32. minimum: 1,
  33. },
  34. maxArgs: {
  35. type: 'number',
  36. minimum: 1,
  37. },
  38. },
  39. additionalProperties: false,
  40. }
  41. ```
  42. ### `alwaysAwait`
  43. Enforces to use `await` inside block statements. Using `return` will trigger a
  44. warning. Returning one line statements with arrow functions is _always allowed_.
  45. Examples of **incorrect** code for the { "alwaysAwait": **true** } option:
  46. ```js
  47. // alwaysAwait: true
  48. test('test1', async () => {
  49. await expect(Promise.resolve(2)).resolves.toBeDefined();
  50. return expect(Promise.resolve(1)).resolves.toBe(1); // `return` statement will trigger a warning
  51. });
  52. ```
  53. Examples of **correct** code for the { "alwaysAwait": **true** } option:
  54. ```js
  55. // alwaysAwait: true
  56. test('test1', async () => {
  57. await expect(Promise.resolve(2)).resolves.toBeDefined();
  58. await expect(Promise.resolve(1)).resolves.toBe(1);
  59. });
  60. test('test2', () => expect(Promise.resolve(2)).resolves.toBe(2));
  61. ```
  62. ### `minArgs` & `maxArgs`
  63. Enforces the minimum and maximum number of arguments that `expect` can take, and
  64. is required to take.
  65. Both of these properties have a default value of `1`, which is the number of
  66. arguments supported by vanilla `expect`.
  67. This is useful when you're using libraries that increase the number of arguments
  68. supported by `expect`, such as
  69. [`jest-expect-message`](https://www.npmjs.com/package/jest-expect-message).
  70. ### Default configuration
  71. The following patterns are considered warnings:
  72. ```js
  73. test('all the things', async () => {
  74. expect();
  75. expect().toEqual('something');
  76. expect('something', 'else');
  77. expect('something');
  78. await expect('something');
  79. expect(true).toBeDefined;
  80. expect(Promise.resolve('hello')).resolves;
  81. expect(Promise.resolve('hello')).resolves.toEqual('hello');
  82. Promise.resolve(expect(Promise.resolve('hello')).resolves.toEqual('hello'));
  83. Promise.all([
  84. expect(Promise.resolve('hello')).resolves.toEqual('hello'),
  85. expect(Promise.resolve('hi')).resolves.toEqual('hi'),
  86. ]);
  87. });
  88. ```
  89. The following patterns are not warnings:
  90. ```js
  91. test('all the things', async () => {
  92. expect('something').toEqual('something');
  93. expect([1, 2, 3]).toEqual([1, 2, 3]);
  94. expect(true).toBeDefined();
  95. await expect(Promise.resolve('hello')).resolves.toEqual('hello');
  96. await Promise.resolve(
  97. expect(Promise.resolve('hello')).resolves.toEqual('hello'),
  98. );
  99. await Promise.all(
  100. expect(Promise.resolve('hello')).resolves.toEqual('hello'),
  101. expect(Promise.resolve('hi')).resolves.toEqual('hi'),
  102. );
  103. });
  104. ```