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.

expect-expect.md 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Enforce assertion to be made in a test body (`expect-expect`)
  2. Ensure that there is at least one `expect` call made in a test.
  3. ## Rule details
  4. This rule triggers when there is no call made to `expect` in a test, to prevent
  5. users from forgetting to add assertions.
  6. Examples of **incorrect** code for this rule:
  7. ```js
  8. it('should be a test', () => {
  9. console.log('no assertion');
  10. });
  11. test('should assert something', () => {});
  12. ```
  13. Examples of **correct** code for this rule:
  14. ```js
  15. it('should be a test', () => {
  16. expect(true).toBeDefined();
  17. });
  18. it('should work with callbacks/async', () => {
  19. somePromise().then(res => expect(res).toBe('passed'));
  20. });
  21. ```
  22. ## Options
  23. ```json
  24. {
  25. "jest/expect-expect": [
  26. "error",
  27. {
  28. "assertFunctionNames": ["expect"]
  29. }
  30. ]
  31. }
  32. ```
  33. ### `assertFunctionNames`
  34. This array option specifies the names of functions that should be considered to
  35. be asserting functions. Function names can use wildcards i.e `request.*.expect`,
  36. `request.**.expect`, `request.*.expect*`
  37. Examples of **incorrect** code for the `{ "assertFunctionNames": ["expect"] }`
  38. option:
  39. ```js
  40. /* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect"] }] */
  41. import { expectSaga } from 'redux-saga-test-plan';
  42. import { addSaga } from '../src/sagas';
  43. test('returns sum', () => {
  44. expectSaga(addSaga, 1, 1).returns(2).run();
  45. });
  46. ```
  47. Examples of **correct** code for the
  48. `{ "assertFunctionNames": ["expect", "expectSaga"] }` option:
  49. ```js
  50. /* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "expectSaga"] }] */
  51. import { expectSaga } from 'redux-saga-test-plan';
  52. import { addSaga } from '../src/sagas';
  53. test('returns sum', () => {
  54. expectSaga(addSaga, 1, 1).returns(2).run();
  55. });
  56. ```
  57. Since the string is compiled into a regular expression, you'll need to escape
  58. special characters such as `$` with a double backslash:
  59. ```js
  60. /* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect\\$"] }] */
  61. it('is money-like', () => {
  62. expect$(1.0);
  63. });
  64. ```
  65. Examples of **correct** code for working with the HTTP assertions library
  66. [SuperTest](https://www.npmjs.com/package/supertest) with the
  67. `{ "assertFunctionNames": ["expect", "request.**.expect"] }` option:
  68. ```js
  69. /* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "request.**.expect"] }] */
  70. const request = require('supertest');
  71. const express = require('express');
  72. const app = express();
  73. describe('GET /user', function () {
  74. it('responds with json', function (done) {
  75. request(app).get('/user').expect('Content-Type', /json/).expect(200, done);
  76. });
  77. });
  78. ```