Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent async describe #18

Closed
louy opened this issue Nov 21, 2017 · 3 comments · Fixed by severest/retrobot#25
Closed

Prevent async describe #18

louy opened this issue Nov 21, 2017 · 3 comments · Fixed by severest/retrobot#25

Comments

@louy
Copy link

louy commented Nov 21, 2017

Thanks for this great plugin!

A mistake I've seen some people make is using an async function for describe, which then makes jest fail silently for a case like the following:

describe('sample case', () => {
  it('works', () => {
    expect(true).toEqual(true);
  });
  describe('async', async () => {
    await new Promise(setImmediate);
    it('breaks', () => {
      throw new Error('Fail');
    });
  });
});

It would be nice to have a rule that prevents this. Same would go for returning a promise (or any other value) inside describe.

describe('sample case', () => {
  it('works', () => {
    expect(true).toEqual(true);
  });
  describe('async', () => {
    return Promise.resolve().then(() => {
      it('breaks', () => {
        throw new Error('Fail');
      });
    });
  });
});

What do you guys think?

@SimenB
Copy link
Member

SimenB commented Nov 22, 2017

I think this makes sense. We should also check for a done callback in describe-blocks.

(Anecdotally the first eslint rule I ever wrote: https://github.com/tlvince/eslint-plugin-jasmine/blob/master/lib/rules/no-suite-callback-args.js)

@SimenB
Copy link
Member

SimenB commented Nov 25, 2017

Also of course check for a return value within describe, and if it's async

@macklinu
Copy link
Collaborator

macklinu commented Feb 3, 2018

I'm interested in contributing this feature - will open a PR for discussion on a WIP implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants