Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 1.88 KB

no-async-describe.md

File metadata and controls

56 lines (38 loc) · 1.88 KB

Disallow async functions passed to describe (mocha/no-async-describe)

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

This rule disallows the use of an async function with describe. It usually indicates a copy/paste error or that you're trying to use describe for setup code, which should happen in before or beforeEach. Also, it can lead to the contained it blocks not being picked up.

Example:

describe('the thing', async function () {
    // This work should happen in a beforeEach:
    const theThing = await getTheThing();

    it('should foo', function () {
        // ...
    });
});

Rule Details

The rule supports "describe", "context" and "suite" suite function names and different valid suite name prefixes like "skip" or "only".

The following patterns are considered problems, whether or not the function uses await:

describe('something', async function () {
    it('should work', function () {});
});

describe('something', async () => {
    it('should work', function () {});
});

If the describe function does not contain await, a fix of removing async will be suggested.

The rule won't be able to detect the (hopefully uncommon) cases where the async function is defined before the describe call and passed by reference:

async function mySuite() {
    it('my test', () => {});
}

describe('my suite', mySuite);

When Not To Use It

  • If you use another library which exposes a similar API as mocha, you should turn this rule off because it would raise warnings.
  • In environments that have not yet adopted ES6 language features (ES3/5).