Skip to content

rejects.toThrow compares only against the message, not the error object #11693

@dankolesnikov

Description

@dankolesnikov

🐛 Bug Report or Feature Request

Unable to match on the object of the error of the rejected promise.

To Reproduce

await expect(axios(badUrl)).rejects.toThrow()

Expected behavior

Being able to access the error object and match on its objects.

await expect(axios(badUrl)).rejects.toThrow( (error) => error.reponse.status === 404)

Essentially I want to do this but without ES Lint yelling at me:

 try {
      await axios(url);
    } catch (error) {
      expect(error.response.status).toBe(404);
    }

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