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

[Bug]: AssertionError is not instanceof Error #15269

Closed
tqhoughton opened this issue Aug 21, 2024 · 3 comments
Closed

[Bug]: AssertionError is not instanceof Error #15269

tqhoughton opened this issue Aug 21, 2024 · 3 comments

Comments

@tqhoughton
Copy link

tqhoughton commented Aug 21, 2024

Version

29.7.0

Steps to reproduce

Use the following jest.config.js:

module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node'
}

Simply create the following test in your node env project:

import { AssertionError } from 'assert'

describe('AssertionError', () =>
  it('should extend the base Error class', () => {
    const foo = new AssertionError({})
    expect(foo instanceof Error).toBeTruthy()
    expect(foo).toBeInstanceOf(AssertionError)
  })
})

Both assertions will fail even though in NodeJS v20 LTS the condition (foo instanceof Error) will resolve to true

Expected behavior

I expect AssertionErrors to extend the standard Error class as they do in the latest LTS version of NodeJS and pass instanceof checks.

Actual behavior

AssertionErrors do not extend the base Error class in NodeJS when running in a jest context.

Additional context

No response

Environment

System:
    OS: macOS 14.6.1
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 20.11.1 - ~/.nvm/versions/node/v20.11.1/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.11.1/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.1/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@soren121
Copy link

Duplicate of #2549

Copy link

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 github-actions bot added the Stale label Sep 25, 2024
Copy link

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 github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants