jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.12k stars 6.44k forks source link

[Bug]: toThrow does not check error cause #15111

Closed DoroGi closed 1 month ago

DoroGi commented 3 months ago

Version

29.7.0

Steps to reproduce

it('should check error cause', () => {
  const fn = () => {
    throw new Error('error message', { cause: { code: '1234' } });
  };
  expect(fn).toThrow({
    name: 'Error',
    message: 'error message',
    cause: { code: 'random string' },
  });
});

Expected behavior

I expect the test above to fail, as the two causes are different. The error message is being checked, but not the cause.

Actual behavior

The test pass independently from the cause field.

Additional context

No response

Environment

System:
  OS: macOS 14.4.1
  CPU: (10) arm64 Apple M1 Pro
Binaries:
  Node: 20.12.2 - /usr/local/bin/node
  npm: 10.5.0 - /usr/local/bin/npm
npmPackages:
  jest: 29.7.0 => 29.7.0
github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 1 month ago

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] commented 3 weeks ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.