Skip to content

export JestAssertionError from expect #15488

Closed as not planned
Closed as not planned
@paul23-git

Description

@paul23-git

🚀 Feature Proposal

export JestAssertionError from expect to allow other packages to import it. This is a clone of #9919 as it's still relevant I think?

Motivation

Given that the expect package is modular and published as a standalone package on npm, I'm using it outside of jest and outside of tests. I'm currently trying to use it for implementing a custom mock server for a dev environment. To properly implement this, I need to distinguish expect exceptions from other exceptions, and thus need to do

if (err instanceof JestAssertionError) {}
However this is not currently possible seen as I can't import JestAssertionError from expect

Example

if (err instanceof JestAssertionError) {
  res.status(400).end()
} else {
  res.status(500).end()
}

Example

It can't come from anywhere else

Pitch

It can't come from anywhere else

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions