Skip to content

returns not override callThrough #2566

@rluvaton

Description

@rluvaton

Describe the bug
returns not override callThrough

To Reproduce
Run the following:

const sinon = require('sinon');
const assert = require('assert');
class A {
	fn() {
		return 1;
	}
}

const a = new A();

sinon.stub(a, 'fn').callThrough().returns(2);

assert.strictEqual(a.fn(), 2);
assert.strictEqual(a.fn(), 2);
assert.strictEqual(a.fn(), 2);
assert.strictEqual(a.fn(), 2);

Expected behavior
this function should return 2 without calling the original function

as resolves and throws does (and maybe even more)

Context (please complete the following information):
The reason I call callThrough is because I have a helper function that stub the function but keeping the result (I know you have spy but stub can provide both override and tracking) or if already stubbed does nothing (so there won't be an error for function already stubbed)

replacing returns with callsFake works as expected

  • Library version: 17.0.0
  • Environment: node

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