Fixed global error handling when the env is executed repeatedly
This commit is contained in:
@@ -1157,12 +1157,21 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
// 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()
|
||||||
);
|
);
|
||||||
const installGlobalErrors = (function() {
|
const { installGlobalErrors, uninstallGlobalErrors } = (function() {
|
||||||
let installed = false;
|
let installed = false;
|
||||||
return function() {
|
|
||||||
if (!installed) {
|
return {
|
||||||
globalErrors.install();
|
installGlobalErrors() {
|
||||||
installed = true;
|
if (!installed) {
|
||||||
|
globalErrors.install();
|
||||||
|
installed = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
uninstallGlobalErrors() {
|
||||||
|
if (installed) {
|
||||||
|
globalErrors.uninstall();
|
||||||
|
installed = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
@@ -2086,9 +2095,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.cleanup_ = function() {
|
this.cleanup_ = function() {
|
||||||
if (globalErrors) {
|
uninstallGlobalErrors();
|
||||||
globalErrors.uninstall();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1011,6 +1011,43 @@ describe('Global error handling (integration)', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('works when the suite is run multiple times', async function() {
|
||||||
|
const global = {
|
||||||
|
...browserEventMethods(),
|
||||||
|
setTimeout: function(fn, delay) {
|
||||||
|
return setTimeout(fn, delay);
|
||||||
|
},
|
||||||
|
clearTimeout: function(fn, delay) {
|
||||||
|
clearTimeout(fn, delay);
|
||||||
|
},
|
||||||
|
queueMicrotask: function(fn) {
|
||||||
|
queueMicrotask(fn);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
|
||||||
|
env.cleanup_();
|
||||||
|
env = new jasmineUnderTest.Env();
|
||||||
|
env.configure({ autoCleanClosures: false });
|
||||||
|
const reporter = jasmine.createSpyObj('fakeReporter', ['specDone']);
|
||||||
|
|
||||||
|
env.addReporter(reporter);
|
||||||
|
|
||||||
|
env.it('fails', function(specDone) {
|
||||||
|
setTimeout(function() {
|
||||||
|
dispatchErrorEvent(global, 'error', { error: 'fail' });
|
||||||
|
specDone();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
await env.execute();
|
||||||
|
reporter.specDone.calls.reset();
|
||||||
|
await env.execute();
|
||||||
|
|
||||||
|
expect(reporter.specDone).toHaveFailedExpectationsForRunnable('fails', [
|
||||||
|
'fail thrown'
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
describe('#spyOnGlobalErrorsAsync', function() {
|
describe('#spyOnGlobalErrorsAsync', function() {
|
||||||
const leftInstalledMessage =
|
const leftInstalledMessage =
|
||||||
'Global error spy was not uninstalled. ' +
|
'Global error spy was not uninstalled. ' +
|
||||||
|
|||||||
@@ -31,12 +31,21 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
// 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()
|
||||||
);
|
);
|
||||||
const installGlobalErrors = (function() {
|
const { installGlobalErrors, uninstallGlobalErrors } = (function() {
|
||||||
let installed = false;
|
let installed = false;
|
||||||
return function() {
|
|
||||||
if (!installed) {
|
return {
|
||||||
globalErrors.install();
|
installGlobalErrors() {
|
||||||
installed = true;
|
if (!installed) {
|
||||||
|
globalErrors.install();
|
||||||
|
installed = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
uninstallGlobalErrors() {
|
||||||
|
if (installed) {
|
||||||
|
globalErrors.uninstall();
|
||||||
|
installed = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
@@ -960,9 +969,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.cleanup_ = function() {
|
this.cleanup_ = function() {
|
||||||
if (globalErrors) {
|
uninstallGlobalErrors();
|
||||||
globalErrors.uninstall();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user