Detect monkey patching and emit a deprecation warning.

This isn't comprehensive but it should be broad enough to ensure that most
people who would be affected by blocking monkey patching see a warning.
Covers the jasmine namespace as well as classes that are monkey patched by
zone.js.

Replacing globals (describe/it/etc) doesn't trigger a warning because they
belong to the user and are expected to be replaced.
This commit is contained in:
Steve Gravrock
2025-11-25 16:54:08 -08:00
parent 32168be6c7
commit 23894c1a0a
15 changed files with 315 additions and 47 deletions

View File

@@ -1,9 +1,12 @@
describe('HtmlReporter', function() {
let env;
let env, deprecator;
beforeEach(function() {
env = new privateUnderTest.Env();
spyOn(env, 'deprecated');
deprecator = jasmine.createSpyObj('deprecator', [
'verboseDeprecations',
'addDeprecationWarning'
]);
env = new privateUnderTest.Env({ deprecator });
});
afterEach(function() {
@@ -21,8 +24,10 @@ describe('HtmlReporter', function() {
});
reporter.initialize();
expect(env.deprecated).toHaveBeenCalledWith(
'HtmlReporter and HtmlSpecFilter are deprecated. Use HtmlReporterV2 instead.'
expect(deprecator.addDeprecationWarning).toHaveBeenCalledWith(
jasmine.anything(),
'HtmlReporter and HtmlSpecFilter are deprecated. Use HtmlReporterV2 instead.',
undefined
);
});