fix: ensure last behavior setter always wins#2682
fix: ensure last behavior setter always wins#2682ordinary9843 wants to merge 1 commit intosinonjs:mainfrom
Conversation
|
Thanks for this, could you rebase on the latest |
|
I think some of these changes will be made redundant by #2670? |
Add resetReturnBehavior() to clear all mutually exclusive return-behavior flags before each setter runs, so the most recently called setter takes effect regardless of invoke priority order in behavior.invoke(). Add tests for previously broken combinations where a higher-priority flag persisted after a lower-priority setter was called.
|
Rebased on latest main. The test suite in On the overlap with #2670: the two address different call orderings. #2670 cleans up setter state when Also worth noting — after #2683, |
Problem
When chaining stub behavior setters, the last call should always win. However, several combinations silently failed because flags set by earlier setters weren't cleared.
For example:
This happens because
behavior.invoke()checksreturnArgAt(priority 2) beforereturnValue(priority 12). WhenreturnsArgis called first, it setsreturnArgAt. Whenreturnsis called next, it setsreturnValuebut leavesreturnArgAtintact — soreturnArgAtstill takes effect.The same issue affects
returnsThis,throwsArg, and any setter that doesn't clear competing state.Fix
Add a
resetReturnBehavior()helper that clears all mutually exclusive return-behavior flags. Call it at the start of each setter so the most recently called setter always takes effect, regardless of the priority order ininvoke().Broken combinations fixed
returnsArgreturnsreturnsThisreturnsthrowsArgreturnsreturnsArgthrowsArgreturnsThisthrowsArgreturnsArgreturnsThisFixes #2656