Skip to content

Error when stubbing a property that does not exist #2629

@DanKaplanSES

Description

@DanKaplanSES

I'd like a more informative error message for this situation:

        const x = {
            getFoo: () => {
                return "bar"
            }
        }

        sinon.stub(x, 'getFoo').value("baz");

        console.log(x.getFoo()); // TypeError: x.getFoo is not a function
        console.log(typeof x.getFoo); // string

The intent here was to stub x's getFoo method, but the user mistakenly used value to do so. In this situation, it would be more helpful for sinon to error on the stub line with an error message similar to: "x.getFoo is a function, not a getter. Use returns instead of value."

I'm aware this is a breaking change, so I think the user would need to configure some sort of "strict mode" to enable an error message like this.

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