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:
@@ -1247,4 +1247,25 @@ describe('Clock (acceptance)', function() {
|
||||
|
||||
clock.tick(400);
|
||||
});
|
||||
|
||||
describe('Warning about monkey patching', function() {
|
||||
for (const name of ['tick', 'mockDate', 'install', 'uninstall']) {
|
||||
it(`warns if Clock#${name} is monkey patched`, function() {
|
||||
spyOn(console, 'error');
|
||||
const clock = new privateUnderTest.Clock({}, function() {}, {});
|
||||
const patch = {};
|
||||
clock[name] = patch;
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
expect(console.error).toHaveBeenCalledOnceWith(
|
||||
jasmine.stringContaining('DEPRECATION: Monkey patching detected.')
|
||||
);
|
||||
// eslint-disable-next-line no-console
|
||||
expect(console.error).toHaveBeenCalledOnceWith(
|
||||
jasmine.stringContaining('ClockSpec.js')
|
||||
);
|
||||
expect(clock[name]).toBe(patch);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user