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

Open
tqhoughton opened this issue Aug 21, 2024 · 1 comment
Open

[Bug]: AssertionError is not instanceof Error #15269

tqhoughton opened this issue Aug 21, 2024 · 1 comment

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

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