From e53e4125048fc4a3ca193a7b49910bc872cbf4fa Mon Sep 17 00:00:00 2001 From: Bogdan Abaev Date: Tue, 26 May 2026 10:54:22 -0700 Subject: [PATCH] use local sinon sandbox to avoid trying to restore sinon on dead reader in later tests --- test/tests/quickCopyTest.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/tests/quickCopyTest.js b/test/tests/quickCopyTest.js index ec3cf79740..1435b66da5 100644 --- a/test/tests/quickCopyTest.js +++ b/test/tests/quickCopyTest.js @@ -459,9 +459,13 @@ describe("Smart copy", function () { describe("Reader tab", function () { var reader; - var hasFocusStub; + // Use a local sandbox: sinon's default sandbox tracks every stub + // forever, so a later `sinon.restore()` elsewhere would + // re-invoke our stub's restore against the already dead reader. + var sandbox; before(async function () { + sandbox = sinon.createSandbox(); reader = await Zotero.Reader.open(attachment.id); await reader._initPromise; await reader._internalReader._primaryView.initializedPromise; @@ -469,7 +473,7 @@ describe("Smart copy", function () { await Zotero.Promise.delay(50); } // Pretend that the reader is focused - hasFocusStub = sinon.stub(reader._iframeWindow.document, 'hasFocus').returns(true); + sandbox.stub(reader._iframeWindow.document, 'hasFocus').returns(true); }); beforeEach(async function () { @@ -477,7 +481,7 @@ describe("Smart copy", function () { }); after(function () { - hasFocusStub.restore(); + sandbox.restore(); }); it("should copy parent citation when nothing is selected in the reader", function () { @@ -487,15 +491,10 @@ describe("Smart copy", function () { }); it("should copy selected annotation", function () { - let stub = sinon.stub(reader, 'getSelectedAnnotationIDs').returns([annotation.key]); - try { - clearClipboard(); - doc.getElementById('key_smartCopy').doCommand(); - assert.include(getClipboardText(), annotation.annotationText); - } - finally { - stub.restore(); - } + sandbox.stub(reader, 'getSelectedAnnotationIDs').returns([annotation.key]); + clearClipboard(); + doc.getElementById('key_smartCopy').doCommand(); + assert.include(getClipboardText(), annotation.annotationText); }); }); });