Don't spy on getGlobal

This commit is contained in:
Steve Gravrock
2025-10-19 09:58:52 -07:00
parent 4201fd848f
commit 020dffd504
4 changed files with 24 additions and 38 deletions

View File

@@ -1226,7 +1226,7 @@ getJasmineRequireObj().Env = function(j$) {
); );
const globalErrors = new GlobalErrors( const globalErrors = new GlobalErrors(
undefined, global,
// Configuration is late-bound because GlobalErrors needs to be constructed // Configuration is late-bound because GlobalErrors needs to be constructed
// before it's set to detect load-time errors in browsers // before it's set to detect load-time errors in browsers
() => this.configuration() () => this.configuration()

View File

@@ -1114,6 +1114,8 @@ describe('Env integration', function() {
global: { global: {
setTimeout: globalSetTimeout, setTimeout: globalSetTimeout,
clearTimeout: clearTimeout, clearTimeout: clearTimeout,
addEventListener() {},
removeEventListener() {},
queueMicrotask: function(fn) { queueMicrotask: function(fn) {
queueMicrotask(fn); queueMicrotask(fn);
} }
@@ -1188,6 +1190,8 @@ describe('Env integration', function() {
clearTimeout: clearTimeout, clearTimeout: clearTimeout,
setInterval: setInterval, setInterval: setInterval,
clearInterval: clearInterval, clearInterval: clearInterval,
addEventListener() {},
removeEventListener() {},
queueMicrotask: function(fn) { queueMicrotask: function(fn) {
queueMicrotask(fn); queueMicrotask(fn);
} }
@@ -2777,10 +2781,9 @@ describe('Env integration', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
const reporter = jasmine.createSpyObj('reporter', [ const reporter = jasmine.createSpyObj('reporter', [
'jasmineDone', 'jasmineDone',
'suiteDone', 'suiteDone',

View File

@@ -25,10 +25,9 @@ describe('Global error handling (integration)', function() {
}, },
onerror: function() {} onerror: function() {}
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
const reporter = jasmine.createSpyObj('reporter', [ const reporter = jasmine.createSpyObj('reporter', [
'jasmineDone', 'jasmineDone',
'suiteDone', 'suiteDone',
@@ -84,7 +83,6 @@ describe('Global error handling (integration)', function() {
}, },
onerror: originalOnerror onerror: originalOnerror
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
const globalErrors = new privateUnderTest.GlobalErrors(global); const globalErrors = new privateUnderTest.GlobalErrors(global);
const onerror = jasmine.createSpy('onerror'); const onerror = jasmine.createSpy('onerror');
globalErrors.pushListener(onerror); globalErrors.pushListener(onerror);
@@ -92,6 +90,7 @@ describe('Global error handling (integration)', function() {
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env({ env = new privateUnderTest.Env({
suppressLoadErrors: true, suppressLoadErrors: true,
global,
GlobalErrors: function() { GlobalErrors: function() {
return globalErrors; return globalErrors;
} }
@@ -127,9 +126,8 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
const reporter = jasmine.createSpyObj('fakeReporter', [ const reporter = jasmine.createSpyObj('fakeReporter', [
'specDone', 'specDone',
'suiteDone' 'suiteDone'
@@ -168,7 +166,6 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
const realClearStack = privateUnderTest.getClearStack(global); const realClearStack = privateUnderTest.getClearStack(global);
const clearStackCallbacks = {}; const clearStackCallbacks = {};
@@ -184,7 +181,7 @@ describe('Global error handling (integration)', function() {
}); });
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
let suiteErrors = []; let suiteErrors = [];
env.addReporter({ env.addReporter({
@@ -232,9 +229,8 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
const reporter = jasmine.createSpyObj('fakeReporter', [ const reporter = jasmine.createSpyObj('fakeReporter', [
'specDone', 'specDone',
'suiteDone' 'suiteDone'
@@ -285,7 +281,6 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
const realClearStack = privateUnderTest.getClearStack(global); const realClearStack = privateUnderTest.getClearStack(global);
const clearStackCallbacks = {}; const clearStackCallbacks = {};
@@ -301,7 +296,7 @@ describe('Global error handling (integration)', function() {
}); });
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
let suiteErrors = []; let suiteErrors = [];
env.addReporter({ env.addReporter({
@@ -353,9 +348,8 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
spyOn(console, 'error'); spyOn(console, 'error');
@@ -396,7 +390,6 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
const realClearStack = privateUnderTest.getClearStack(global); const realClearStack = privateUnderTest.getClearStack(global);
let clearStackCallCount = 0; let clearStackCallCount = 0;
@@ -419,7 +412,7 @@ describe('Global error handling (integration)', function() {
spyOn(console, 'error'); spyOn(console, 'error');
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
const receivedErrors = []; const receivedErrors = [];
function logErrors(event) { function logErrors(event) {
@@ -471,9 +464,8 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
const reporter = jasmine.createSpyObj('fakeReporter', [ const reporter = jasmine.createSpyObj('fakeReporter', [
'specDone', 'specDone',
'suiteDone' 'suiteDone'
@@ -514,7 +506,6 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
const realClearStack = privateUnderTest.getClearStack(global); const realClearStack = privateUnderTest.getClearStack(global);
const clearStackCallbacks = {}; const clearStackCallbacks = {};
@@ -530,7 +521,7 @@ describe('Global error handling (integration)', function() {
}); });
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
let suiteErrors = []; let suiteErrors = [];
env.addReporter({ env.addReporter({
@@ -578,9 +569,8 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
const reporter = jasmine.createSpyObj('fakeReporter', [ const reporter = jasmine.createSpyObj('fakeReporter', [
'specDone', 'specDone',
'suiteDone' 'suiteDone'
@@ -633,7 +623,6 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
const realClearStack = privateUnderTest.getClearStack(global); const realClearStack = privateUnderTest.getClearStack(global);
const clearStackCallbacks = {}; const clearStackCallbacks = {};
@@ -649,7 +638,7 @@ describe('Global error handling (integration)', function() {
}); });
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
let suiteErrors = []; let suiteErrors = [];
env.addReporter({ env.addReporter({
@@ -701,9 +690,8 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
spyOn(console, 'error'); spyOn(console, 'error');
@@ -746,7 +734,6 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
const realClearStack = privateUnderTest.getClearStack(global); const realClearStack = privateUnderTest.getClearStack(global);
let clearStackCallCount = 0; let clearStackCallCount = 0;
@@ -770,7 +757,7 @@ describe('Global error handling (integration)', function() {
spyOn(console, 'error'); spyOn(console, 'error');
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
const receivedErrors = []; const receivedErrors = [];
function logErrors(event) { function logErrors(event) {
@@ -831,9 +818,8 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
env.configure({ detectLateRejectionHandling: true }); env.configure({ detectLateRejectionHandling: true });
reporter = jasmine.createSpyObj('fakeReporter', [ reporter = jasmine.createSpyObj('fakeReporter', [
@@ -978,9 +964,7 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); env = new privateUnderTest.Env({ global });
env.cleanup_();
env = new privateUnderTest.Env();
env.configure({ detectLateRejectionHandling: true }); env.configure({ detectLateRejectionHandling: true });
const reporter = jasmine.createSpyObj('fakeReporter', [ const reporter = jasmine.createSpyObj('fakeReporter', [
'specDone', 'specDone',
@@ -1024,9 +1008,8 @@ describe('Global error handling (integration)', function() {
queueMicrotask(fn); queueMicrotask(fn);
} }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
env.cleanup_(); env.cleanup_();
env = new privateUnderTest.Env(); env = new privateUnderTest.Env({ global });
env.configure({ autoCleanClosures: false }); env.configure({ autoCleanClosures: false });
const reporter = jasmine.createSpyObj('fakeReporter', ['specDone']); const reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);

View File

@@ -28,7 +28,7 @@ getJasmineRequireObj().Env = function(j$) {
); );
const globalErrors = new GlobalErrors( const globalErrors = new GlobalErrors(
undefined, global,
// Configuration is late-bound because GlobalErrors needs to be constructed // Configuration is late-bound because GlobalErrors needs to be constructed
// before it's set to detect load-time errors in browsers // before it's set to detect load-time errors in browsers
() => this.configuration() () => this.configuration()