Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.15 KB

valid-expect-in-promise.md

File metadata and controls

51 lines (38 loc) · 1.15 KB

Require promises that have expectations in their chain to be valid (vitest/valid-expect-in-promise)

⚠️ This rule warns in the 🌐 all config.

This rule flags any promises within the body of a test that include expectations that have either not been returned or awaited.

The following patterns is considered warning:

test('promise test', async () => {
  something().then((value) => {
    expect(value).toBe('red');
  });
});

test('promises test', () => {
  const onePromise = something().then((value) => {
    expect(value).toBe('red');
  });
  const twoPromise = something().then((value) => {
    expect(value).toBe('blue');
  });

  return Promise.any([onePromise, twoPromise]);
});

The following pattern is not warning:

test('promise test', async () => {
  await something().then((value) => {
    expect(value).toBe('red');
  });
});

test('promises test', () => {
  const onePromise = something().then((value) => {
    expect(value).toBe('red');
  });
  const twoPromise = something().then((value) => {
    expect(value).toBe('blue');
  });

  return Promise.all([onePromise, twoPromise]);
});