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(
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()

View File

@@ -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',

View File

@@ -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']);

View File

@@ -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()