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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Suggest using `expect.assertions()` OR `expect.hasAssertions()` (`prefer-expect-assertions`)
  2. Ensure every test to have either `expect.assertions(<number of assertions>)` OR
  3. `expect.hasAssertions()` as its first expression.
  4. ## Rule details
  5. This rule triggers a warning if,
  6. - `expect.assertions(<number of assertions>)` OR `expect.hasAssertions()` is not
  7. present as first statement in a test, e.g.:
  8. ```js
  9. test('my test', () => {
  10. expect(someThing()).toEqual('foo');
  11. });
  12. ```
  13. - `expect.assertions(<number of assertions>)` is the first statement in a test
  14. where argument passed to `expect.assertions(<number of assertions>)` is not a
  15. valid number, e.g.:
  16. ```js
  17. test('my test', () => {
  18. expect.assertions('1');
  19. expect(someThing()).toEqual('foo');
  20. });
  21. ```
  22. ### Default configuration
  23. The following patterns are considered warnings:
  24. ```js
  25. test('my test', () => {
  26. expect.assertions('1');
  27. expect(someThing()).toEqual('foo');
  28. });
  29. test('my test', () => {
  30. expect(someThing()).toEqual('foo');
  31. });
  32. ```
  33. The following patterns would not be considered warnings:
  34. ```js
  35. test('my test', () => {
  36. expect.assertions(1);
  37. expect(someThing()).toEqual('foo');
  38. });
  39. test('my test', () => {
  40. expect.hasAssertions();
  41. expect(someThing()).toEqual('foo');
  42. });
  43. ```
  44. ## Options
  45. #### `onlyFunctionsWithAsyncKeyword`
  46. When `true`, this rule will only warn for tests that use the `async` keyword.
  47. ```json
  48. {
  49. "rules": {
  50. "jest/prefer-expect-assertions": [
  51. "warn",
  52. { "onlyFunctionsWithAsyncKeyword": true }
  53. ]
  54. }
  55. }
  56. ```
  57. When `onlyFunctionsWithAsyncKeyword` option is set to `true`, the following
  58. pattern would be a warning:
  59. ```js
  60. test('my test', async () => {
  61. const result = await someAsyncFunc();
  62. expect(result).toBe('foo');
  63. });
  64. ```
  65. While the following patterns would not be considered warnings:
  66. ```js
  67. test('my test', () => {
  68. const result = someFunction();
  69. expect(result).toBe('foo');
  70. });
  71. test('my test', async () => {
  72. expect.assertions(1);
  73. const result = await someAsyncFunc();
  74. expect(result).toBe('foo');
  75. });
  76. ```