Skip to content

New rule proposal, prefer mockReturnValue over mockImplementation #1674

Open
@geoffswift

Description

@geoffswift

We are seeing examples likes this

// BAD
example.mockImplementation(() => value);

Rather than just

// GOOD
example.mockReturnValue(value);

This seems to be a sound change to make when

  • value is a literal primitive e.g. true
  • A const primitive value

In more complex values using mockImplementation may be approprate, e.g. the result is deferred or closures a var etc

// OK
example.mockImplementation(() => new Date());

// NOT THE SAME
example.mockReturnValue(new Date());

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