source: frontend/node_modules/eslint-plugin-jest/docs/rules/valid-describe-callback.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[9af201e]1# Enforce valid `describe()` callback (`valid-describe-callback`)
2
3Using an improper `describe()` callback function can lead to unexpected test
4errors.
5
6## Rule Details
7
8This rule validates that the second parameter of a `describe()` function is a
9callback function. This callback function:
10
11- should not be
12 [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
13- should not contain any parameters
14- should not contain any `return` statements
15
16The following `describe` function aliases are also validated:
17
18- `describe`
19- `describe.only`
20- `describe.skip`
21- `fdescribe`
22- `xdescribe`
23
24The following patterns are considered warnings:
25
26```js
27// Async callback functions are not allowed
28describe('myFunction()', async () => {
29 // ...
30});
31
32// Callback function parameters are not allowed
33describe('myFunction()', done => {
34 // ...
35});
36
37//
38describe('myFunction', () => {
39 // No return statements are allowed in block of a callback function
40 return Promise.resolve().then(() => {
41 it('breaks', () => {
42 throw new Error('Fail');
43 });
44 });
45});
46
47// Returning a value from a describe block is not allowed
48describe('myFunction', () =>
49 it('returns a truthy value', () => {
50 expect(myFunction()).toBeTruthy();
51 }));
52```
53
54The following patterns are not considered warnings:
55
56```js
57describe('myFunction()', () => {
58 it('returns a truthy value', () => {
59 expect(myFunction()).toBeTruthy();
60 });
61});
62```
Note: See TracBrowser for help on using the repository browser.