Skip to content

jest/require-to-throw-message Correctness ​

What it does ​

This rule triggers a warning if toThrow() or toThrowError() is used without an error message.

Example ​

javascript
// invalid
test("all the things", async () => {
  expect(() => a()).toThrow();
  expect(() => a()).toThrowError();
  await expect(a()).rejects.toThrow();
  await expect(a()).rejects.toThrowError();
});

// valid
test("all the things", async () => {
  expect(() => a()).toThrow("a");
  expect(() => a()).toThrowError("a");
  await expect(a()).rejects.toThrow("a");
  await expect(a()).rejects.toThrowError("a");
});

References ​

Released under the MIT License.