Skip to content

[jest-mock] Return value is not recorded if mock implementation throws an error #5761

@UselessPickles

Description

@UselessPickles

Do you want to request a feature or report a bug?
Bug in new feature that I created :(

What is the current behavior?
If a jest mock function throws an error, the .mock.returnValues array is not updated with an entry for that call to the mock. This causes the returnValues array to become out of sync with all other parallel arrays in the structure (calls, instances, etc).

Original new feature ticket: #5738
Original new feature PR: #5752

If the current behavior is a bug, please provide the steps to reproduce
Should be obvious. I'll add a new unit test to reproduce it before fixing it.

What is the expected behavior?
The the parallel arrays in the mock function's mock structure should always have matching lengths. When a mock function implementation throws an error, a value of undefined should be pushed onto the mock.returnValues array.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Irrelevant

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions