From 631c27ad471085c26fbb8c2ce441ed1feb36526d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E8=83=9C?= <2318857637@qq.com> Date: Thu, 11 Jun 2026 10:53:50 +0800 Subject: [PATCH] fix: let returns override returnsArg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王胜 <2318857637@qq.com> --- src/sinon/default-behaviors.js | 1 + test/src/stub-test.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/src/sinon/default-behaviors.js b/src/sinon/default-behaviors.js index df5a00a76..82368b667 100644 --- a/src/sinon/default-behaviors.js +++ b/src/sinon/default-behaviors.js @@ -145,6 +145,7 @@ const defaultBehaviors = { returns: function returns(fake, value) { fake.callsThrough = false; fake.returnValue = value; + fake.returnArgAt = undefined; fake.resolve = false; fake.reject = false; fake.returnValueDefined = true; diff --git a/test/src/stub-test.js b/test/src/stub-test.js index adc016925..157026f44 100644 --- a/test/src/stub-test.js +++ b/test/src/stub-test.js @@ -721,6 +721,15 @@ describe("stub", function () { assert.equals(obj.fn("myarg"), "myarg"); }); + it("is superseded by returns", function () { + const stub = createStub(); + + stub.returnsArg(0); + stub.returns(42); + + assert.equals(stub("myarg"), 42); + }); + it("throws if no index is specified", function () { const stub = createStub();