From 020dffd5043a1b6e08864e541d1e3cdb759d6f59 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Sun, 19 Oct 2025 09:58:52 -0700 Subject: [PATCH] Don't spy on getGlobal --- lib/jasmine-core/jasmine.js | 2 +- spec/core/integration/EnvSpec.js | 7 ++- .../integration/GlobalErrorHandlingSpec.js | 51 +++++++------------ src/core/Env.js | 2 +- 4 files changed, 24 insertions(+), 38 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index a287f50f..113e8619 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1226,7 +1226,7 @@ getJasmineRequireObj().Env = function(j$) { ); const globalErrors = new GlobalErrors( - undefined, + global, // Configuration is late-bound because GlobalErrors needs to be constructed // before it's set to detect load-time errors in browsers () => this.configuration() diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index f37c0bba..b57b8d00 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -1114,6 +1114,8 @@ describe('Env integration', function() { global: { setTimeout: globalSetTimeout, clearTimeout: clearTimeout, + addEventListener() {}, + removeEventListener() {}, queueMicrotask: function(fn) { queueMicrotask(fn); } @@ -1188,6 +1190,8 @@ describe('Env integration', function() { clearTimeout: clearTimeout, setInterval: setInterval, clearInterval: clearInterval, + addEventListener() {}, + removeEventListener() {}, queueMicrotask: function(fn) { queueMicrotask(fn); } @@ -2777,10 +2781,9 @@ describe('Env integration', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); const reporter = jasmine.createSpyObj('reporter', [ 'jasmineDone', 'suiteDone', diff --git a/spec/core/integration/GlobalErrorHandlingSpec.js b/spec/core/integration/GlobalErrorHandlingSpec.js index 95d206eb..b9e77bb2 100644 --- a/spec/core/integration/GlobalErrorHandlingSpec.js +++ b/spec/core/integration/GlobalErrorHandlingSpec.js @@ -25,10 +25,9 @@ describe('Global error handling (integration)', function() { }, onerror: function() {} }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); const reporter = jasmine.createSpyObj('reporter', [ 'jasmineDone', 'suiteDone', @@ -84,7 +83,6 @@ describe('Global error handling (integration)', function() { }, onerror: originalOnerror }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); const globalErrors = new privateUnderTest.GlobalErrors(global); const onerror = jasmine.createSpy('onerror'); globalErrors.pushListener(onerror); @@ -92,6 +90,7 @@ describe('Global error handling (integration)', function() { env.cleanup_(); env = new privateUnderTest.Env({ suppressLoadErrors: true, + global, GlobalErrors: function() { return globalErrors; } @@ -127,9 +126,8 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); const reporter = jasmine.createSpyObj('fakeReporter', [ 'specDone', 'suiteDone' @@ -168,7 +166,6 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); const realClearStack = privateUnderTest.getClearStack(global); const clearStackCallbacks = {}; @@ -184,7 +181,7 @@ describe('Global error handling (integration)', function() { }); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); let suiteErrors = []; env.addReporter({ @@ -232,9 +229,8 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); const reporter = jasmine.createSpyObj('fakeReporter', [ 'specDone', 'suiteDone' @@ -285,7 +281,6 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); const realClearStack = privateUnderTest.getClearStack(global); const clearStackCallbacks = {}; @@ -301,7 +296,7 @@ describe('Global error handling (integration)', function() { }); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); let suiteErrors = []; env.addReporter({ @@ -353,9 +348,8 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); spyOn(console, 'error'); @@ -396,7 +390,6 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); const realClearStack = privateUnderTest.getClearStack(global); let clearStackCallCount = 0; @@ -419,7 +412,7 @@ describe('Global error handling (integration)', function() { spyOn(console, 'error'); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); const receivedErrors = []; function logErrors(event) { @@ -471,9 +464,8 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); const reporter = jasmine.createSpyObj('fakeReporter', [ 'specDone', 'suiteDone' @@ -514,7 +506,6 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); const realClearStack = privateUnderTest.getClearStack(global); const clearStackCallbacks = {}; @@ -530,7 +521,7 @@ describe('Global error handling (integration)', function() { }); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); let suiteErrors = []; env.addReporter({ @@ -578,9 +569,8 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); const reporter = jasmine.createSpyObj('fakeReporter', [ 'specDone', 'suiteDone' @@ -633,7 +623,6 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); const realClearStack = privateUnderTest.getClearStack(global); const clearStackCallbacks = {}; @@ -649,7 +638,7 @@ describe('Global error handling (integration)', function() { }); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); let suiteErrors = []; env.addReporter({ @@ -701,9 +690,8 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); spyOn(console, 'error'); @@ -746,7 +734,6 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); const realClearStack = privateUnderTest.getClearStack(global); let clearStackCallCount = 0; @@ -770,7 +757,7 @@ describe('Global error handling (integration)', function() { spyOn(console, 'error'); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); const receivedErrors = []; function logErrors(event) { @@ -831,9 +818,8 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); env.configure({ detectLateRejectionHandling: true }); reporter = jasmine.createSpyObj('fakeReporter', [ @@ -978,9 +964,7 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); - env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); env.configure({ detectLateRejectionHandling: true }); const reporter = jasmine.createSpyObj('fakeReporter', [ 'specDone', @@ -1024,9 +1008,8 @@ describe('Global error handling (integration)', function() { queueMicrotask(fn); } }; - spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env.cleanup_(); - env = new privateUnderTest.Env(); + env = new privateUnderTest.Env({ global }); env.configure({ autoCleanClosures: false }); const reporter = jasmine.createSpyObj('fakeReporter', ['specDone']); diff --git a/src/core/Env.js b/src/core/Env.js index ad39d25c..5cfbeed4 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -28,7 +28,7 @@ getJasmineRequireObj().Env = function(j$) { ); const globalErrors = new GlobalErrors( - undefined, + global, // Configuration is late-bound because GlobalErrors needs to be constructed // before it's set to detect load-time errors in browsers () => this.configuration()