Skip to content

Conversation

@thamion
Copy link
Contributor

@thamion thamion commented Dec 2, 2025

Purpose (TL;DR) - mandatory

Sandbox restore is not restoring functions stubbed by stub(func). This PR aligns the behaviour of stuband restore.

Background (Problem in detail) - optional

This is an issue when stubbing, for example, axios instances. Those are build in a way that looses their original object prototype. stub(axios) will work fine and stub all methods as expected, but restore wont work.

Solution - optional

The issue can be fixed by aligning the sandbox code

sinon/lib/sinon/sandbox.js

Lines 410 to 411 in 2605504

const isSpyingOnEntireObject =
typeof property === "undefined" && typeof object === "object";

with the stub code

sinon/lib/sinon/stub.js

Lines 91 to 94 in 2605504

const isObjectOrFunction =
typeof object === "object" || typeof object === "function";
const isStubbingEntireObject =
typeof property === "undefined" && isObjectOrFunction;

How to verify - mandatory

  1. Check out this branch
  2. npm install
  3. npm run test

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached.

@fatso83 fatso83 merged commit 13b27cc into sinonjs:main Dec 19, 2025
9 checks passed
@fatso83
Copy link
Contributor

fatso83 commented Dec 19, 2025

Ran the sauce labs test locally. Works fine. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants