Skip to content

Latest commit

 

History

History
62 lines (49 loc) · 1.26 KB

no-confusing-set-timeout.md

File metadata and controls

62 lines (49 loc) · 1.26 KB

Disallow confusing usages of jest.setTimeout (no-confusing-set-timeout)

While jest.setTimeout can be called multiple times anywhere within a single test file only the last call before any test functions run will have an effect.

Rule details

this rule checks for several confusing usages of jest.setTimeout that looks like it applies to specific tests within the same file, such as:

  • being called anywhere other than in global scope
  • being called multiple times
  • being called after other Jest functions like hooks, describe, test, or it

Examples of incorrect code for this rule:

describe('test foo', () => {
  jest.setTimeout(1000);
  it('test-description', () => {
    // test logic;
  });
});

describe('test bar', () => {
  it('test-description', () => {
    jest.setTimeout(1000);
    // test logic;
  });
});

test('foo-bar', () => {
  jest.setTimeout(1000);
});

describe('unit test', () => {
  beforeEach(() => {
    jest.setTimeout(1000);
  });
});

Examples of correct code for this rule:

jest.setTimeout(500);
test('test test', () => {
  // do some stuff
});
jest.setTimeout(1000);
describe('test bar bar', () => {
  it('test-description', () => {
    // test logic;
  });
});